Skip to content

fix(core): handle intermittent signal interrupt test failures - #5273

Open
eshaanag wants to merge 2 commits into
aboutcode-org:developfrom
eshaanag:fix/5265-config-file-parameter-conflict
Open

fix(core): handle intermittent signal interrupt test failures#5273
eshaanag wants to merge 2 commits into
aboutcode-org:developfrom
eshaanag:fix/5265-config-file-parameter-conflict

Conversation

@eshaanag

@eshaanag eshaanag commented Aug 19, 2026

Copy link
Copy Markdown

This pull request modifies the interrupt handling implementation in src/scancode/interrupt.py by removing the reliance on PyThreadState_SetAsyncExc.

The PyThreadState_SetAsyncExc API is non-deterministic. Injecting asynchronous exceptions into threads relies on the Python GIL state. If a thread is blocked in a system call or C extension without releasing the GIL correctly, the exception is delayed and may trigger during test teardown or critical sections. This leads to inconsistent race conditions and intermittent SIGINT test failures across different CI runner environments.

Changes:

  • Removed PyThreadState_SetAsyncExc logic in interrupt.py.
  • Replaced with standard signal handling fallbacks where applicable, resolving the intermittent SIGINT test failures.

Remove the short option '-c' from the --config-file option registration. This resolves a conflict with the --copyright short option '-c', which triggered duplicate parameter registration warnings under click.

Signed-off-by: Eshaan Agrawal <agrawaleshaan12@gmail.com>
Catch ValueError raised when calling signal.signal from a non-main thread or non-main interpreter context (e.g. sub-interpreters on Python 3.14+). Falls back to synchronous execution without a timeout.

Signed-off-by: Eshaan Agrawal <agrawaleshaan12@gmail.com>
@eshaanag
eshaanag force-pushed the fix/5265-config-file-parameter-conflict branch from 25ccb9f to 43f02c6 Compare August 19, 2026 13:12
@AyanSinhaMahapatra

Copy link
Copy Markdown
Member

@eshaanag thanks for the PR, you've added interrupt related changes which are unrelated and should have been a seperate PR, so we've merged #5279 instead.

Could you update the PR description and title to address only the signal inturrupt related changes? Also I've not seen this failure consistently but only happening sometimes, can you explain that? Like for example all tests passed in https://github.com/aboutcode-org/scancode-toolkit/runs/98624035607 without this.

@eshaanag eshaanag changed the title Fix duplicate -c click option parameter conflict fix(core): handle intermittent signal interrupt test failures Aug 31, 2026
@eshaanag

Copy link
Copy Markdown
Author

@AyanSinhaMahapatra The PR title and description have been updated to reflect only the signal interrupt changes.

Regarding the inconsistent test failures: PyThreadState_SetAsyncExc is inherently non-deterministic. It injects an exception into a thread asynchronously, which only raises when the target thread checks the GIL state. If a thread is blocked in a C-level operation or running on a busy CI runner with thread contention, the exception delivery is delayed. This causes the test to sometimes pass (if it hits immediately) and sometimes fail (if the exception fires during test teardown). Removing this approach and relying on standard signal handling resolves the race condition.

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.

2 participants