Flush the connectionRead buffer before throwing connectionClosed.
When the response-data has already been read into the buffer, the connection is closed, and the data already read is sufficient, an exception is thrown and the data cannot be read.
In my case, I am using http-client in haskell/servant. The program can not read response data using getResponse and makeLengthReader. I think https://github.com/haskell-servant/servant/issues/994 might be related, but it's closed for some reason and I'm not sure how to fix it.
This PR flushes the connectionRead buffer before throwing connectionClosed.
When the response-data has already been read into the buffer, the connection is closed
Are you saying that after
connectionReadconnectionUnreadconnectionClose
you expect a subsequent connectionRead to succeed?
If yes, then I'm not convinced that this is "reasonable" to expect.
I think a better solution might be to identify where and when connectionClose was called prematurely, and addressed this.
you expect a subsequent connectionRead to succeed?
Yes.
In my case, the HTTP response has an HTTP header and body. After parsing the header, connectionUnread is called and the body is returned to the stack. After that, the body needs to be read with connectionRead, but since the connection has already been closed, an exception is thrown and the body remains unread.
This series of processes cannot be controlled from the application.
but since the connection has already been closed, an exception is thrown and the body remains unread
Do you know where the connection is closed?
After rerunning it with +RTS -xc, share the stack trace.