Skip to content

fix(spool): treat a client hangup after the full body as complete - #455

Open
ravi-pplx wants to merge 3 commits into
block:mainfrom
perplexityai:fix/spool-complete-after-hangup
Open

ravi-pplx wants to merge 3 commits into
block:mainfrom
perplexityai:fix/spool-complete-after-hangup

Conversation

@ravi-pplx

@ravi-pplx ravi-pplx commented Nov 21, 2026 •

Copy link
Copy Markdown

When a spool reader has written the full declared Content-Length to its client, Serve still waits for the fill to finish, including the cache commit, before it returns. Clients usually hang up as soon as they have the body, which cancels the request during that wait, so Serve returns context.Canceled for a response that was delivered in full. As a result:

  • the handler logs Failed to serve shared response at error level;
  • the git strategy logs Failed to serve snapshot via spool, records the follower wait as read_error, and skips the snapshot serve metric.

Change

  • Serve returns success when the request ends after the full declared body was written and flushed, and the request was still live when the last flush returned.
  • Flushes go through http.ResponseController, and a flush error is returned instead of ignored.
  • The liveness check covers middleware that wraps the ResponseWriter with only http.Flusher, such as otelhttp, which hides flush errors. On HTTP/1.1, net/http cancels the request context as soon as a write to the connection fails.
  • Unchanged: a client that leaves before the body is complete still gets the context error, responses without a Content-Length behave as before, and fill failures seen while the client is connected are still reported.

Testing

  • TestClientHangupAfterFullBodyIsComplete serves a 4-byte body to a recorder. A request cancelled after half of it gets context.Canceled, and one cancelled after all of it gets success. It runs in a synctest bubble, so the hangup always lands after Serve has settled.
  • TestClientHangupAfterFailedSocketWriteIsIncomplete uses a real httptest.Server whose connection fails its second write, once with the server's ResponseWriter and once behind an http.Flusher-only wrapper. Both must report an error. Without the liveness check, the wrapped case reports success.
  • Manual check: a real server and http.Client that reads the body and closes the connection while the fill is still committing, through an http.Flusher-only wrapper. 500 of 500 requests are reported as successes.

Created with Perplexity

@ravi-pplx
ravi-pplx requested a review from a team as a code owner November 21, 2026 19:47
@ravi-pplx
ravi-pplx requested review from alecthomas and removed request for a team November 21, 2026 19:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T18:32:51.771547Z b5a8cab Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ravi-pplx
ravi-pplx force-pushed the fix/spool-complete-after-hangup branch from 84b98ed to a16076a Compare November 21, 2026 19:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84b98eddf5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/spool/group.go Resolved
A spool reader that has written the whole declared Content-Length still
waits for the fill to finish, which includes committing the cache
write. Clients usually close the connection as soon as they have the
body, so the wait is cancelled and Serve returns context.Canceled for a
response that was delivered in full. Callers then log it as a failed
response.

Serve now returns success when the request ends after the full
declared body was written and flushed. A client that leaves before the
body is complete still gets the context error, and a failed flush is
returned instead of being ignored.

Signed-off-by: Ravi Agarwal <ravi@perplexity.ai>
Co-authored-by: Perplexity <noreply@perplexity.ai>
@ravi-pplx
ravi-pplx force-pushed the fix/spool-complete-after-hangup branch from a16076a to a483383 Compare November 21, 2026 21:26
Signed-off-by: Ravi Agarwal <ravi@perplexity.ai>
Co-authored-by: Perplexity <noreply@perplexity.ai>
@ravi-pplx

Copy link
Copy Markdown
Author

@codex review

Created with Perplexity

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3196189f25

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/spool/group_test.go Resolved
Signed-off-by: Ravi Agarwal <ravi@perplexity.ai>
Co-authored-by: Perplexity <noreply@perplexity.ai>
@ravi-pplx

Copy link
Copy Markdown
Author

@codex review

Created with Perplexity

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: b5a8cab563

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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.

1 participant