Skip to content

Instantly share code, notes, and snippets.

@potatosalad
potatosalad / README.md
Last active August 25, 2018 19:07
Possible race condition in Concuerror with ETS

Concuerror (version 0.20.0+build.2149.refc040b0d):

./concuerror --pa "$(exenv prefix)/lib/elixir/ebin" -m registry_example -t test --treat_as_normal=killed --treat_as_normal=shutdown --show_races=true --graph=registry_example.dot

Example failure:

* Stop testing on first error. (Check '-h keep_going').
@potatosalad
potatosalad / README.md
Last active August 25, 2018 15:31
Possible race condition in ETS

The registry_example.ex test spawns two child processes who both attempt to register themselves against a unique Registry.

Only one should succeed. However, there seem to be cases when :ets.insert_new/2 returns true for two independent processes.

Example reproduction of the bug:

# This is on Erlang/OTP 21.0 and Elixir 1.7.2
# However, I was able to confirm the same behavior on master for both.
elixirc registry_example.ex
defmodule ErlangLogger do
@moduledoc """
Designed to mirror [`kernel/include/logger.hrl`](https://github.com/erlang/otp/blob/da166b76de977171243dd2ea7f86b98f451fabc5/lib/kernel/include/logger.hrl)
*WARNING:* Currently blows up if `__CALLER__` does not have a valid `mfa`
"""
defmacro log_emergency(a) do
do_log(:emergency, [a], __CALLER__)
end
defmodule ExampleEncryptor do
def encrypt(plain_text, password) do
salt = :crypto.strong_rand_bytes(32)
iterations = 4096
kek = derive_key_encryption_key(password, salt, iterations, 32, :sha512)
kiv = :crypto.strong_rand_bytes(12)
cek = :crypto.strong_rand_bytes(32)
civ = :crypto.strong_rand_bytes(12)
{cek_cipher_text, cek_cipher_tag} = :crypto.block_encrypt(:aes_gcm, kek, kiv, {<<>>, cek})

The following module can be placed in the root level of elixir-lang/elixir and executed using the following:

bin/elixirc keyword_delete_bench.ex && erl -noshell -pa . -pa lib/elixir/ebin -s 'keyword_delete_bench'

Example (minimized output):

## count=100000, size=10

There's something out of whack with the consistent hash algorithm used by swarm (libring):

Add 4 nodes all weighted equally (should be 4 x 25%) libring

iex> ring = HashRing.new()
iex> ring = HashRing.add_node(ring, :a@nohost)
iex> ring = HashRing.add_node(ring, :b@nohost)
iex> ring = HashRing.add_node(ring, :c@nohost)
iex&gt; ring = HashRing.add_node(ring, :d@nohost)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
crc_3_gsm
crc_3_rohc
crc_4_interlaken
crc_4_itu
crc_5
crc_5_epc
crc_5_itu
crc_5_usb
crc_6_cdma2000_a
crc_6_cdma2000_b
@potatosalad
potatosalad / results.txt
Last active August 31, 2017 19:26
Possible issue with AC binary split
=== Test case: binary_module_SUITE:random_ref_sr_comp/1 (click for source code)
=== Config value:
[{watchdog,<0.222.0>},
{tc_logfile,"/home/andrew/otp/release/tests/test_server/ct_run.test_server@antergos.2017-08-31_09.57.16/tests.stdlib_test.binary_module_SUITE.logs/run.2017-08-31_10.03.13/binary_module_suite.random_ref_sr_comp.html"},
{tc_group_properties,[{suite,binary_module_SUITE}]},
{tc_group_path,[]},
{data_dir,"/home/andrew/otp/release/tests/stdlib_test/binary_module_SUITE_data/"},
{priv_dir,"/home/andrew/otp/release/tests/test_server/ct_run.test_server@antergos.2017-08-31_09.57.16/tests.stdlib_test.binary_module_SUITE.logs/run.2017-08-31_10.03.13/log_private/"},
@potatosalad
potatosalad / iam_assert.erl
Last active August 24, 2017 17:10
Snippets from unreleased IAM erlang library
%% -*- mode: erlang; tab-width: 4; indent-tabs-mode: 1; st-rulers: [70] -*-
%% vim: ts=4 sw=4 ft=erlang noet
%%%-------------------------------------------------------------------
%%% @author Andrew Bennett <andrew@pixid.com>
%%% @copyright 2017, Andrew Bennett
%%% @doc
%%%
%%% @end
%%% Created : 24 Apr 2017 by Andrew Bennett <andrew@pixid.com>
%%%-------------------------------------------------------------------