-
Notifications
You must be signed in to change notification settings - Fork 263
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
Throw exception on "peer closed" event #937
base: master
Are you sure you want to change the base?
Conversation
In my understanding, the @bgamari Did you consider the uploading scenario? |
Hmm, this is an interesting point, @kazu-yamamoto; I had not considered the uploading case. This indeed complicates matters as we certainly do not want to terminate any handlers until they have at very least had a change to read and process the input sent by the client. Consequently, I suspect the exception should not be delivered until the handler has declared that it is "done" with the connection; the idea here is that then "pure" handlers (e.g. pure queries, not uploads) could signal immediately that they are done with the connection. I can think of at least two concrete interfaces by which this could be done. For instance, one could imagine that type Application =
Request
-- ^ the request
-> (Response -> IO ResponseReceieved)
-- ^ respond to the request
-> IO ()
-- ^ signal that the handler is finished reading from the request
-> IO () Alternatively, we could make this a property of the requestFinishedReading :: Request -> IO () Given that changing |
@@ -59,6 +66,14 @@ socketConnection _ s = do | |||
bufferPool <- newBufferPool 2048 16384 | |||
writeBuffer <- createWriteBuffer 16384 | |||
writeBufferRef <- newIORef writeBuffer | |||
#if MIN_VERSION_base(4,18,0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is not good enough as error
is called by GHC on macOS.
I don't think I understand your idea. |
There are two kinds of applications.
|
Since HTTP/1.1 uses persist connections, clients rarely uses |
Sure. The idea is that distinguishing between your cases (1) and (2) in general handleQuery :: Application
handleQuery request respond = do
-- indicate that the handler can be safely killed if the client shuts down
-- the connection
connectionIsInactive request
-- this may be a long computation
result <- computeQueryResult
sendResponse respond result When the client closes their end of the connection, Naturally, ensuring that this is not racy in the face of connection reuse is
Note above that I am not terribly familiar with HTTP/2. My understanding is that it allows |
OK. It seems to me that this is a right direction. HTTP/2 clients does not use @bgamari Would you put this implementation forward? |
@kazu-yamamoto, I have pushed an initial implementation. By the way, please do ignore |
Looks good.
|
I am reluctant to make this platform dependent since we may implement Currently GHC will throw an exception if you attempt to register for
|
Right. The combination of |
Could we add the flag to the closeOnClientDisconnect :: Application -> Application
closeOnClientDisconnect app req respond = do
setupDisconnectCheck $ requestClientClosedConnectionFlag req
app req respond or closeOnClientDisconnect :: Request -> IO ()
closeOnClientDisconnect = setupDisconnectCheck . requestClientClosedConnectionFlag Where the |
This is a prototype enabling support for the
evtPeerClosed
event being introduced into GHC's event manager. This allowswarp
to throw aPeerClosedException
exception to handler threads for connections which have been prematurely closed.See ghc!11080 and ghc#23825
To do
@since
declarations to the Haddock