Skip to content

fix(expert_credo): prevent infinite hang in with_stdin/2#372

Merged
doorgan merged 1 commit into
expert-lsp:mainfrom
QuinnWilton:fix/expert-credo-with-stdin-hang
Jun 24, 2026
Merged

fix(expert_credo): prevent infinite hang in with_stdin/2#372
doorgan merged 1 commit into
expert-lsp:mainfrom
QuinnWilton:fix/expert-credo-with-stdin-hang

Conversation

@QuinnWilton

@QuinnWilton QuinnWilton commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

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/2 causes the spawning process to hang indefinitely while waiting for a message from the spawned process, and preventing Credo diagnostics from being updated.

Solution

Replace spawn/1 with spawn_monitor/1, and add a receive clause to handle the spawned process unexpectedly terminating before sending a result.

In the successful case, the monitor is flushed to avoid :DOWN messages building up and causing a mailbox leak.

A 30 second timeout is also added, to prevent buggy or broken Credo modules from causing the entire system to hang.

@mhanberg mhanberg closed this Feb 10, 2026
@mhanberg mhanberg reopened this 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.

@doorgan doorgan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to fix the issue described, although I don't think we are currently giving expert_credo the proper support it needs. We still need better support for plugins, see #270.

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.
@doorgan doorgan force-pushed the fix/expert-credo-with-stdin-hang branch from 5b3ef4d to 07b94c0 Compare June 24, 2026 21:21
@doorgan doorgan merged commit 811578b into expert-lsp:main Jun 24, 2026
48 checks passed
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.

3 participants