Throw exception on "peer closed" event#937
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 |
| bufferPool <- newBufferPool 2048 16384 | ||
| writeBuffer <- createWriteBuffer 16384 | ||
| writeBufferRef <- newIORef writeBuffer | ||
| #if MIN_VERSION_base(4,18,0) |
There was a problem hiding this comment.
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 resultWhen 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 respondor closeOnClientDisconnect :: Request -> IO ()
closeOnClientDisconnect = setupDisconnectCheck . requestClientClosedConnectionFlagWhere the |
This is a prototype enabling support for the
evtPeerClosedevent being introduced into GHC's event manager. This allowswarpto throw aPeerClosedExceptionexception to handler threads for connections which have been prematurely closed.See ghc!11080 and ghc#23825
To do
@sincedeclarations to the Haddock