json: avoid duplicate response after write failures - #1100
Merged
Conversation
JSON response writes may fail only after the successful status has already been committed. Treat the controlled response types as serializable and avoid attempting a second error response, which cannot change the status and produces a superfluous WriteHeader warning. Amp-Thread-ID: https://ampcode.com/threads/T-019fa815-b759-72ab-9771-e4008fbbf378
keegancsmith
marked this pull request as ready for review
July 28, 2026 10:48
burmudar
approved these changes
Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The JSON search and list handlers currently treat every encoder error as though an HTTP 500 can still be sent. In practice, the response types are known to serialize successfully, while transport failures occur after
ResponseWriter.Writehas already committed HTTP 200. CallingjsonErrorat that point cannot change the response and causes thehttp: superfluous response.WriteHeader callwarning reported in #1099.This routes both successful response types through a small helper that encodes directly to the response writer and intentionally ignores encoder errors. Direct encoding retains the encoder’s pooled buffer behavior and avoids the response-sized copy that pre-marshalling would require. The existing
application/jsonheader is set rather than appended.Fixes #1099