Skip to content

Stop Mox.allow/3 looping on a dead owner - #181

Merged
josevalim merged 1 commit into
dashbitco:mainfrom
mvanhorn:fix/179-mox-allow-dead-owner
Nov 7, 2026
Merged

josevalim merged 1 commit into
dashbitco:mainfrom
mvanhorn:fix/179-mox-allow-dead-owner

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Motivation

A caller that tries to share a mock from an owner that has already exited never gets a result back. The call keeps running and allocating until the runtime runs out of memory.

A :not_allowed error from NimbleOwnership was treated as the mock not being initialized for that owner. The handler wrote an empty entry and called allow again, and the call is followed by another expression so it is not tail recursive. A dead owner, or one that exits before the allowance is recorded, still returns :not_allowed, so the retry never stops.

What this changes

allow/3 now forwards to do_allow/4 with a retried? flag that starts false. The first :not_allowed still initializes the owner entry and retries once. A second :not_allowed raises ArgumentError, saying the owner process is not alive when that pid is dead and that it does not own the mock otherwise. The docs and changelog describe that failure.

How it was tested

A run with the mox change reverted gave no clear result, so no test is shown to catch this bug. The changed test test/mox_test.exs did not run here: no test runner for it was available.

Closes #179

allow/3 now forwards to do_allow/4 with a retried? flag that starts
false. The first :not_allowed still initializes the owner entry and
retries once. A second :not_allowed raises ArgumentError, saying the
owner process is not alive when that pid is dead and that it does not
own the mock otherwise. The docs and changelog describe that failure.

Fixes dashbitco#179
@josevalim
josevalim merged commit 97df51a into dashbitco:main Nov 7, 2026
2 checks passed
@mvanhorn

mvanhorn commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging this, @josevalim. Good to know Mox.allow/3 now raises on a dead owner instead of looping until the VM runs out of memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mox.allow on a dead process causes infinite looping

2 participants