Skip to content

chunked disconnect now throws InvalidChunkHeaders#578

Open
goertzenator wants to merge 3 commits into
snoyberg:mainfrom
goertzenator:fixChunkedDisconnect
Open

chunked disconnect now throws InvalidChunkHeaders#578
goertzenator wants to merge 3 commits into
snoyberg:mainfrom
goertzenator:fixChunkedDisconnect

Conversation

@goertzenator

Copy link
Copy Markdown

Fixes 11 year old issue #168

We observed a IncompleteHeaders exception after connecting to a streaming endpoint for an hour with a server initiated disconnect. That is rather misleading, so this PR changes that to InvalidChunkHeaders.

The readline functions and call sites were also improved.

All tests pass.

@goertzenator

Copy link
Copy Markdown
Author

Some tests from conduit failing. Standby...

@goertzenator

Copy link
Copy Markdown
Author

I think this PR is in good shape now. Some CI tests are failing, but it looks like dependency rot (correct me if I'm wrong) which has nothing to do with this PR.

@sol

sol commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

@goertzenator sorry for the delay, I'll try to get to this eventually.

- Fixes issue snoyberg#168
- Was previously throwing `IncompleteHeaders` which is confusing and misleading.
-  Untangles readLine functions and call sites.
@sol sol force-pushed the fixChunkedDisconnect branch from e8795bb to cefb5eb Compare June 7, 2026 15:29
@sol

sol commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

@goertzenator I may wanna do a small refactoring before changing this code. Would you be willing to rebase your code after I do that (there will be conflicts)?

@goertzenator

Copy link
Copy Markdown
Author

For sure, go for it.

@sol sol left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

First things first, overall, I like this change.

Your code does two things:

  1. Refactoring: Effectively getting rid of connectionReadLineWith, which I like, as it removes some code duplication in connectionReadLine. However, I'm not sure if it's possible to do that while keeping the existing behavior (see my comment on nextStatusLine).
  2. Fix the exception semantics for chunked body readers. You communicate the failure condition via the return value, which I think in general is preferable. However, in this specific case we always turn Nothing into throwHttp at the call site. So I think maybe instead pass in the error type, and keep the calls to throwHttp where they currently are. I think doing so, will allow you to do (2) before (1).

To sum things up, this is what I propose:

  • One PR that only does (2), addressing the issue by passing through the error type (HttpExceptionContent).
  • If you're then still up for it, a separate PR that does (1), the refactoring (remove the code duplication in connectionReadLine). In that PR we can then solely focus on what to do about nextStatusLine.

connectionReadLineWith mhl conn bs >>= parseStatus mhl 3
mbs <- connectionReadLineMaybe mhl conn
case mbs of
Nothing -> throwHttp NoResponseDataReceived

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think, strictly speaking, this changes existing behavior.

Specifically, if I'm not mistaken, NoResponseDataReceived can now be thrown even after some data has been received (some data without CRLF, then empty chunk).

@goertzenator

Copy link
Copy Markdown
Author

Thanks for taking a close look at it. I'm deep into some other stuff right now, but I hope to get back to it in within a week.

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