Skip to content
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

Monitor acceptLoopDo #3299

Merged
merged 1 commit into from
Aug 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ run errroPolicyTrace acceptPolicyTrace socket acceptedConnectionLimit acceptExce
resQ <- STM.newTQueueIO
threadsVar <- STM.newTVarIO Set.empty
let acceptLoopDo = acceptLoop acceptPolicyTrace resQ threadsVar statusVar acceptedConnectionLimit beginConnection applicationStart acceptException socket
-- The accept loop is killed when the main loop stops.
mainDo = Async.withAsync acceptLoopDo $ \_ ->
mainLoop errroPolicyTrace resQ threadsVar statusVar complete main
-- The accept loop is killed when the main loop stops and the main
-- loop is killed if the accept loop stops.
mainDo = mainLoop errroPolicyTrace resQ threadsVar statusVar complete main
killChildren = do
children <- STM.atomically $ STM.readTVar threadsVar
forM_ (Set.toList children) Async.cancel
-- After both the main and accept loop have been killed, any remaining
-- spawned threads are cancelled.
mainDo `finally` killChildren
(snd <$> Async.concurrently acceptLoopDo mainDo) `finally` killChildren