fix(service): Return 400 for client-side upload stream errors#374
Merged
fix(service): Return 400 for client-side upload stream errors#374
Conversation
When a client drops the connection mid-upload, the stream error was propagating as Error::Io and returning 500. The server is not at fault in this case. Introduces ClientError and ClientStream as a distinct type from the outgoing PayloadStream. All backends now call unpack_client_error() after a failed put, which walks the error source chain (handling both direct ClientError sources and those packed inside an io::Error) and maps them to the new Error::Client variant. The server maps this to 400 Bad Request. MeteredPayloadStream and meter_stream are now generic over the stream and error type, avoiding an extra box and unifying metering for both incoming and outgoing streams. Co-Authored-By: Claude <noreply@anthropic.com>
matt-codecov
approved these changes
Mar 13, 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.
When a client drops the connection mid-upload, the broken stream error was propagating as
Error::Ioand returning 500. The server is not at fault here — this should be a 400.Dedicated stream type
Introduces
ClientErrorandClientStreamas a distinct type from the outgoingPayloadStream. Previously, both incoming and outgoing streams wereBoxStream<'static, io::Result<Bytes>>, making it impossible to distinguish a client-side failure from a backend I/O error at the type level.ClientStreamis now the type for all incoming request bodies.ClientErrorwraps the underlying axum/hyper body error and isClone(backed byArc).Distinct status code
Adds
Error::Client(ClientError)to the service error enum. The server maps this variant to400 Bad Request, while all other I/O errors remain 500.Unpacking client errors
Backends receive a
ClientStream, convert it into areqwest::Bodyorio::Readerfor storage, and need to detect when a failure was caused by the client rather than the backend.common::unpack_client_errorwalks the error source chain and checks two locations: the error itself (directClientError), and customio::Errorpayloads (whereStreamReaderor reqwest/hyper may have wrapped it). All backends now call this after a failed put and returnError::Clientwhen the source was the upload stream.Generics
Several stream utilities were generalised over the stream and error type:
SizedPeek— previously hardcoded toPayloadStream; now avoids intermediate boxingMeteredPayloadStreamandServices::meter_stream— now a single generic implementation that works for both stream types and avoids an extra innerBox