fix(expert_credo): prevent infinite hang in with_stdin/2#372
Merged
doorgan merged 1 commit intoJun 24, 2026
Merged
Conversation
This was referenced Feb 10, 2026
doorgan
pushed a commit
that referenced
this pull request
Jun 24, 2026
This is part of a set of 4 PRs that arose out of some static analysis tooling I'm working on: - #369 - #370 - #371 - #372 That means that these aren't crashes or issues that I've observed in practice, however based on my reading of the code, they do represent issues worth addressing. ## Problem: `Beams.apply_to_all/2` spawns its worker process using a bare `spawn/1`, and then blocks in `block_until_done/3` until it receives a `:progress` message from it. If the worker crashes, this message will never arrive, and the caller will block indefinitely. ## Solution Replace `spawn/1` with `spawn_monitor/1`, and add a `receive` clause in `block_until_done/3` to handle the worker unexpectedly terminating before a `:progress` message is sent, so that we're able to immediately raise instead of blocking forever. In the successful case, the monitor is flushed to avoid `:DOWN` messages building up and causing a mailbox leak.
Replace bare spawn with spawn_monitor so the caller receives a
{:DOWN, ...} message if the spawned process crashes, instead of
blocking in receive forever.
Add a 30-second timeout as a safety net against indefinite hangs.
5b3ef4d to
07b94c0
Compare
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.
This is part of a set of 4 PRs that arose out of some static analysis tooling I'm working on:
That means that these aren't crashes or issues that I've observed in practice, however based on my reading of the code, they do represent issues worth addressing.
Problem:
This is effectively the same issue as in #370, where the use of a bare
spawn/2causes the spawning process to hang indefinitely while waiting for a message from the spawned process, and preventingCredodiagnostics from being updated.Solution
Replace
spawn/1withspawn_monitor/1, and add areceiveclause to handle the spawned process unexpectedly terminating before sending a result.In the successful case, the monitor is flushed to avoid
:DOWNmessages building up and causing a mailbox leak.A 30 second timeout is also added, to prevent buggy or broken
Credomodules from causing the entire system to hang.