[SPARK-55930][SPARK-55931][CONNECT] Byte-aware gRPC metadata size checks and errorClassFallback#54728
Open
othon2000 wants to merge 3 commits intoapache:masterfrom
Open
[SPARK-55930][SPARK-55931][CONNECT] Byte-aware gRPC metadata size checks and errorClassFallback#54728othon2000 wants to merge 3 commits intoapache:masterfrom
othon2000 wants to merge 3 commits intoapache:masterfrom
Conversation
hvanhovell
reviewed
Mar 11, 2026
| str | ||
| } else { | ||
| val budget = maxBytes - sizeInBytes(abbrevMarker) | ||
| val buf = StandardCharsets.UTF_8.encode(str) |
Contributor
There was a problem hiding this comment.
Can we try to be a bit more careful with allocations. sizeInBytes(..) and this call both encode the string to bytes. At this point you have allocated 3 ByteBuffers. Can we bring it down to 1?
Author
There was a problem hiding this comment.
I removed one. To remove both, the implementation was quite convoluted. LMK if this is enough.
hvanhovell
reviewed
Mar 11, 2026
sql/connect/server/src/test/scala/org/apache/spark/sql/connect/utils/ErrorUtilsSuite.scala
Outdated
Show resolved
Hide resolved
Author
|
The implementation still contains a bug, where we are checking individual metadata fields against the limit but not their sum. Needs to be fixed. |
…ameters exceed size limit When messageParameters JSON exceeds the maxMetadataSize limit, surface the error class via a separate errorClassFallback metadata key to allow proxy inspection without interfering with the FetchErrorDetails client/server flow. Adds ErrorUtilsSuite to cover buildStatusFromThrowable behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…elds Replace character-length checks with UTF-8 byte size checks when enforcing the gRPC metadata size limit. Multi-byte characters (e.g. CJK) can cause length-based checks to undercount the actual byte size sent on the wire. - Add `sizeInBytes` and `abbreviateByBytes` to `SparkStringUtils` - Use `sizeInBytes` when checking `messageParameters` against the limit - Use `abbreviateByBytes` when truncating `stackTrace` to the limit Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
This was fixed by 1fce674 |
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.
What changes were proposed in this pull request?
This PR addresses two related issues in
ErrorUtilsaround gRPC metadata size enforcement:[SPARK-55930] Byte-aware size checks (
SparkStringUtils)sizeInBytesandabbreviateByByteshelpers toSparkStringUtilssizeInByteswhen checkingmessageParametersagainst the metadata size limitabbreviateByByteswhen truncatingstackTraceto the limit[SPARK-55931] Add
errorClassFallbackmetadata keyWhen
messageParametersJSON exceedsmaxMetadataSize, surface the error class via a separateerrorClassFallbackmetadata key so proxy/interceptor systems can inspect the error classwithout interfering with the existing
FetchErrorDetailsclient/server flow.[EXTRA]: Metadata byte count should take into account all metadata fields, instead of individual ones
Previous implementation checked individual metadata lengths against
CONNECT_GRPC_MAX_METADATA_SIZE,now we check all fields combined
Why are the changes needed?
Character-length-based checks undercount the actual byte size of gRPC metadata payloads when
multi-byte characters (e.g. CJK) are present, potentially causing
MESSAGE_SIZE_LIMIT_EXCEEDEDerrors at the transport layer: essentially an error when throwing an error, which is a debugging hell.
Additionally, when
messageParametersare dropped due to size limits, there was no way forobservability or proxy layers to recover the error class from the metadata.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Added
ErrorUtilsSuitecoveringbuildStatusFromThrowablebehavior, including:errorClassFallbackpropagation whenmessageParametersexceed the limitExtended
SparkStringUtilswith unit tests forsizeInBytesandabbreviateByBytes.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Co-authored by Claude Sonnet 4.6