mandar1045

mandar1045

I’ve been fixing race condition / crash bugs in an open source org, for a few months now and almost all of them had the same problem. They only happen with a very specific order of events (process crashes mid-message, a reply arrives late, a timer fires at the wrong moment) so the normal ExUnit tests never catch them. We find them in prod, then I spend a day trying to reproduce it and 20 minutes fixing it.

So I started reading about how FoundationDB and TigerBeetle deal with this. They do “deterministic simulation testing”: run the whole system inside a simulator that controls time, message order, randomness and crashes, run it thousands of times with different seeds, and when something breaks you get a seed that replays the exact same failure every time.

I couldn’t find anything like this for Elixir and I’m thinking of building it. Very rough idea of what a test could look like:

simtest "cache stays consistent when workers crash", runs: 1_000 do
  start_supervised!(MyApp.CacheSupervisor)

  Sim.spawn_clients(10, fn -> MyApp.Cache.put(random_key(), random_value()) end)

  Sim.inject(:crash, MyApp.Cache.Worker, probability: 0.05)
  Sim.inject(:delay_messages, max: :timer.seconds(2))
  Sim.advance(:timer.minutes(10))

  assert MyApp.Cache.consistent?()
end

and when it fails you’d get the seed plus the smallest set of events that still breaks it, something like:

failed on run 412 (seed 8812734019)
shrunk to:
  1. worker 2 receives {:put, "a", 1}
  2. worker 2 crashes before replying
  3. supervisor restarts it, client retries the put

My plan for how it works: in test env, rewrite modules at compile time so send/receive, timers, monotonic_time and :rand go through a fake scheduler instead of the real one. Concuerror does something kind of similar for Erlang but it’s aimed at exhaustively exploring interleavings, not seeded fault injection with virtual time, and using it from Elixir is painful (at least it was for me).

Other stuff I looked at: gen_server_virtual_time and Klotho (both nice but only handle time), and StreamData (seeds, but for data not scheduling). If something already does all of this please tell me before I sink weeks into it lol.

Things I’m not sure about:

  • is compile time rewriting going to be too fragile? the alternative is making people use a special GenServer-ish behaviour, which feels worse to me but maybe it’s more realistic
  • I’m planning single node first and network partitions / multi node later. does that order make sense?
  • what would you need to see before trusting something like this? my idea is to run it against some well known libs and see if it finds real bugs

Also curious if you’ve had bugs like this in prod and how you ended up reproducing them.

If there’s a reason this can’t work on the BEAM I’d rather hear it now .

Showing Posts 1 to 6

jstimps

jstimps

Check out eta:

Erlang support was released in 0.1.0. Elixir support is on main but hasn’t been released yet.

Eta is still early, but I have been working to prove it’s efficacy in real projects, and have found several real bugs both in my own code and in open projects.

The basic idea of eta is that it suspends all the processes under test and schedules them one at a time using a deterministic scheduler.

It’s most effective when combined with a formal model like TLA+ and a checker like TLC. The model checks your design and DST can help confirm your code matches your design.

That modeling effort, combined with the writing of the DST harness means that formal verification requires a significant time investment in the development of your project, but in my experience it produces high quality bug reports for elusive defects, especially when paired with a capable LLM.

I’m currently working on an implementation of Flexible Paxos, with a large suite of formal verification backing it.

ausimian

ausimian

A process that I (the clankers) experimented with recently was:

  1. Spec in TLA+
  2. Model checking
  3. TLAPS proofs (mostly clankers)
  4. Pure functional state machine via gen_statem. Effects such as message sending are strictly returned through {next_event, internal, …}
  5. Some stateful property testing, hand-rolled, but I’m interested in trying out the new PropertyDamage library to replace this.

The final thing - the bit I thought was reasonably novel - was to get the clankers to emit TLC-compatible traces from the running code, and get TLC to validate them against the spec (see below).

The cool thing is you can just use erlang tracing to capture the handle_event entry and exit, which gets you a long way to producing the trace - no further instrumentation required.

jstimps

jstimps

Agreed, avoiding deep instrumentation is preferable. And especially if your system under test is already deterministic, you’re unlikely to need a framework to help.

However nondeterminism coming from outside a pure function (scheduling, network, disk, timers, etc) is where DST projects like eta are trying to help. Quick note on scheduling: I don’t know if the BEAM scheduler is actually deterministic or not, but from the perspective of the developer, I think we must treat it as nondet since we have little control over its low level decisions.

Trace validation looks like another great way to link code to a formal model.

gtcode

gtcode

I’ve been looking into this recently. Some resources beyond eta:

PULSE (Quviq, QuickCheck-based) is worth looking at for earlier work on instrumented Erlang with randomized, replayable scheduling. Haven’t qualified it with current Elixir/OTP, though. eta’s README also explains where instrumentation stops by default: Task/Agent need additional instrumentation.

Quint Connect for Elixir is clearly worth a look. Different approach: generate traces from spec, then replay actions against Elixir implementation.

PropEr’s state-machine testing handles command generation, parallel histories and shrinking. Perhaps this is reusable here. Shrinking commands however isn’t the same as shrinking the schedule and injected faults while ensuring a reproducible failure mode. Parallel runs also go through the real BEAM scheduler, so PropEr alone doesn’t give you replay of a specific interleaving.

For trust, I’d want to see the simulator catch a retry applying the same write twice after a worker crashes before replying, or an old reply changing state after a restart, then replay the shrunk failure.

I’ve also been wondering how much of Lynx could eventually cover deterministic testing. I’m experimenting with Lynx and Lean 4 in Hold Ledger, and I’ve been holding off on learning TLA+/Quint, while Lynx features stabilize. Lynx already has concurrency machinery. Having said that, distributed nodes aren’t modeled, proofs don’t include external sockets or ports, and timers cover possible orderings, not wall-clock deadlines. Currently, the docs describe sequential verification as the focus.

I’m not expecting Lynx to become a DST framework. I’m wondering how much overlap there might be in terms of bug coverage with regard to the concurrency proofs it can cover. If I can prove a property across the interleavings that a runtime model would allow, there could be less of a need for exploring scheduling arrangements for a property. From there, the question might be whether the model covers the relevant behaviors and failure modes. Thus why I’m waiting to see where Lynx lands before investing in TLA+/Quint.

Quint specifically seems interesting as a more forward thinking design relevant to AI driven workflows, which is a separate topic. It could supply scenarios and expected results for DST. Might be worth exploring if Quint Connect’s spec-generated traces could drive an eta harness, so scheduling and network fault injection come from eta. This would need the spec to account for the faults eta injects, but if so it could save writing a separate model just for the test harness. Shrinking the Quint action sequence might still need separate work.

jstimps

jstimps

The walkthrough doc for Elixir below shows the complete end-to-end process of implementing eta, finding a planted bug in a simple consensus system (an ABD Quorum Register), demonstrating replay, shrinking, narrative building, and fault injection.

Lynx looks cool, I’ll have to spend some time grokking it.

gtcode

gtcode

Thanks, my bad for not perusing the guides.

I found the supervisor section here: gotchas. If a codebase uses Supervisor, Registry or :supervisor without instrumenting them, the children they spawn can stay suspended and the run can end looking clean. Eta.Beam.instrument/1 fixes it.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

sntran
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
SyntaxSorcerer
This is the start of my Elixir learning journal/journey. I plan to share my journey in this thread and am open to all feedback, construct...
New
bartblast
This is where the projects in the Hologram Showcase get posted: apps built with Hologram and libraries made for it. New ones go up usuall...
New
karolina.curiosum
Hi everyone! This is our fourth edition. Last year, 1,000+ developers took part. The more of you who answer, the more useful the results...
New
budgie
Never used it. I know it’s well-liked by some and the authors have put a lot of work into it. Aside from that, is there a community cons...
New
mandar1045
I’ve been fixing race condition / crash bugs in an open source org, for a few months now and almost all of them had the same problem. The...
New
fredwu
Over the years I’ve tried dozens of time tracking and invoicing apps, and Harvest was the only one I liked. Primarily due to its relative...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
261 13183 112
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
charlenopires
Hi everyone :waving_hand: I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New
PJUllrich
On November 23, 2026, an unauthorized third party exploited a vulnerability in hex.pm (CVE-2026-129514, CVSS 10.0) that let them run comm...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews