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

withHandle #1015

Merged
merged 4 commits into from
Nov 22, 2024
Merged

withHandle #1015

merged 4 commits into from
Nov 22, 2024

Conversation

kazu-yamamoto
Copy link
Contributor

This implements rule 2 of #1014.
Relating to #1013.

@kazu-yamamoto kazu-yamamoto requested a review from Vlix November 21, 2024 07:46
-- | Registering a timeout action and unregister its handle
-- when the body action is finished.
withHandle :: Manager -> TimeoutAction -> (Handle -> IO a) -> IO a
withHandle mgr onTimeout action =
Copy link
Contributor

Choose a reason for hiding this comment

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

withHandle mgr onTimeout =
    E.bracket (register mgr onTimeout) cancel

@@ -106,10 +106,6 @@ http2server label settings ii transport addr app h2req0 aux0 response = do
logResponse req st msiz
mapM_ (logPushPromise req) pps
Left e
-- killed by the local worker manager
| Just E.ThreadKilled <- E.fromException e -> return ()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is now not caught anymore, right? Is that intentional?

withHandleKillThread only catches the T.TimeoutThread

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is very old code.
Currenlty, killThread is not used anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

But people can implement their own forking behaviour with settingsFork. So it COULD happen that a ThreadKilled is thrown to this thread.

Though now that I think about it, this is actually better, right? Since if someone would want to kill an HTTP thread that's handling a request, this would just ignore the signal. So I now also believe this is the right decision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that ThreadKilled was tried to be caught only in HTTP/2.
If we worry about it, we should catch it in HTTP/1.1, too.

-- unregister its handle when the body action is killed or finished.
withHandleKillThread :: Manager -> TimeoutAction -> (Handle -> IO ()) -> IO ()
withHandleKillThread mgr onTimeout action =
E.handle handler $ E.bracket (registerKillThread mgr onTimeout) cancel action
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better/worse to do the following? 🤔

E.bracket (registerKillThread mgr onTimeout) cancel $ E.handle handler action

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting.
I don't know which is better.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it will matter much... since the cancel will be run either way.

The difference is this, effectively:

-- Here's the body of 'bracket'

-- either here instead of:
-- mask $ \restore -> do
E.handle handler $ mask $ \restore -> do
  a <- before
  -- or here instead of:
  -- r <- restore (thing a) `onException` after a
  r <- restore (E.handle handler $ thing a) `onException` after a
  _ <- after a
  return r

@kazu-yamamoto kazu-yamamoto merged commit 0efd19b into yesodweb:master Nov 22, 2024
14 checks passed
@kazu-yamamoto kazu-yamamoto deleted the with-handle branch November 22, 2024 00:24
@kazu-yamamoto
Copy link
Contributor Author

Thank you for reviewing.

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