Skip to content

Conversation

@Major-333
Copy link

What is this PR about?
This PR fixes a race condition where the timeout timer callback writes to already closed stdout or stderr channels, resulting in a panic: send on closed channel error.

Why is this change necessary?
When a timeout occurs, the timer callback (time.AfterFunc) writes an error message to the stderr channel and kills the process. However, if the stderr channel has already been closed (e.g., by the caller in RunPython3Code), this leads to a runtime panic.
The issue arises because timer.Stop() does not prevent an already-triggered timer callback from executing.

What changes have been made?
• Added a sync.WaitGroup to track the timer callback execution.
• Ensured that if timer.Stop() fails (indicating the timer has already triggered), the main process waits for the timer callback to finish before closing the channels.

@Major-333
Copy link
Author

@Yeuoly

Copy link
Collaborator

@Yeuoly Yeuoly left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix!

@Major-333
Copy link
Author

Hi @Yeuoly

Thanks for approving the PR! It looks like the workflow is still pending approval to run. When you have a moment, could you approve it under the Actions tab?

Much appreciated!

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