Repository navigation
Stop Mox.allow/3 looping on a dead owner - #181
Merged
Merged
Conversation
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
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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