Skip to content

Conversation

@junjihashimoto
Copy link
Contributor

@junjihashimoto junjihashimoto commented May 25, 2025

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 haskell-servant/servant#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.

@sol
Copy link
Collaborator

sol commented Jun 3, 2025

When the response-data has already been read into the buffer, the connection is closed

Are you saying that after

  1. connectionRead
  2. connectionUnread
  3. connectionClose

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.

@junjihashimoto
Copy link
Contributor Author

junjihashimoto commented Jun 3, 2025

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.

@sol
Copy link
Collaborator

sol commented Jun 3, 2025

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?

@junjihashimoto
Copy link
Contributor Author

After rerunning it with +RTS -xc, share the stack trace.

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