Skip to content

fix(agent): refactor trackScriptLogs to avoid deadlock #8084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 20, 2023

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Jun 19, 2023

During agent close it was possible for the startup script logs consumer
to enter a deadlock state where by agent close was waiting via
a.trackConnGoroutine and the log reader for a flush event.

This refactor removes the mutex in favor of channel communication and
relies on two goroutines without shared state.

https://github.com/coder/coder/actions/runs/5313851600/jobs/9620310022?pr=8082

NOTE: Observe PR target is not main.

@mafredri mafredri force-pushed the mafredri/fix-startup-script-track-logs branch from 6c9c1ad to fe53927 Compare June 19, 2023 17:47
@mafredri mafredri changed the title fix(agent): refacor trackScriptLogs to avoid deadlock fix(agent): refactor trackScriptLogs to avoid deadlock Jun 19, 2023
@mafredri mafredri marked this pull request as ready for review June 19, 2023 17:56
@mafredri mafredri requested review from kylecarbs and mtojek June 19, 2023 17:56
@mafredri mafredri force-pushed the mafredri/fix-startup-script-track-logs branch from fe53927 to 2798ecd Compare June 19, 2023 18:56
Base automatically changed from mafredri/refactor-startup-script-eof-to-start-end to main June 20, 2023 11:41
During agent close it was possible for the startup script logs consumer
to enter a deadlock state where by agent close was waiting via
`a.trackConnGoroutine` and the log reader for a flush event.

This refactor removes the mutex in favor of channel communication and
relies on two goroutines without shared state.
@mafredri mafredri force-pushed the mafredri/fix-startup-script-track-logs branch from 2798ecd to 3913854 Compare June 20, 2023 11:43
@mafredri mafredri force-pushed the mafredri/fix-startup-script-track-logs branch 2 times, most recently from 6f66e6e to 78c478c Compare June 20, 2023 12:33
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

@mafredri thoughts on moving this into agentsdk? External packages like envbuilder and envbox use almost the exact same code, so it'd be good to keep it all race-free.

@mafredri
Copy link
Member Author

@mafredri thoughts on moving this into agentsdk? External packages like envbuilder and envbox use almost the exact same code, so it'd be good to keep it all race-free.

Sure, I can take a stab at it! 👍🏻

@mafredri
Copy link
Member Author

I'll merging this now and submit a separate PR which breaks this up into agentsdk.

@mafredri mafredri merged commit ea4b7d6 into main Jun 20, 2023
@mafredri mafredri deleted the mafredri/fix-startup-script-track-logs branch June 20, 2023 15:05
@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants