Fix broken EULA download due to zstd compression level mismatch#296
Fix broken EULA download due to zstd compression level mismatch#296
Conversation
|
@copilot retry |
Co-authored-by: thesprockee <962164+thesprockee@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a regression where EVR EULA downloads fail to decompress on the client due to inconsistent zstd encoder configuration in StreamJson.
Changes:
- Align
StreamJsonzstd writer options withStreamJSONRawMessageby usingzstd.WithEncoderLevel(1). - Add ZstdCompression round-trip tests for both
StreamJSONRawMessageandStreamJson.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| server/evr/core_stream.go | Ensures ZstdCompression uses the expected zstd encoder level for JSON streaming. |
| server/evr/core_stream_test.go | Adds ZstdCompression tests for JSON/raw-message streaming paths. |
| func TestEasyStream_StreamJson_ZstdCompression(t *testing.T) { | ||
| // Test with a struct similar to EULADocument | ||
| type TestDoc struct { | ||
| Type string `json:"type"` | ||
| Lang string `json:"lang"` | ||
| Text string `json:"text"` | ||
| } | ||
|
|
||
| // Test data | ||
| original := TestDoc{ | ||
| Type: "eula", | ||
| Lang: "en", | ||
| Text: "This is a test EULA document with some content.", | ||
| } | ||
|
|
||
| // Test with null termination | ||
| buf := new(bytes.Buffer) | ||
| stream := &EasyStream{ | ||
| Mode: EncodeMode, | ||
| w: buf, | ||
| } | ||
|
|
||
| if err := stream.StreamJson(original, true, ZstdCompression); err != nil { | ||
| t.Fatalf("failed to encode with ZstdCompression: %v", err) | ||
| } | ||
|
|
||
| encoded := buf.Bytes() | ||
| if len(encoded) == 0 { | ||
| t.Fatal("encoded data is empty") | ||
| } | ||
|
|
||
| // Decode and verify | ||
| stream = &EasyStream{ | ||
| Mode: DecodeMode, | ||
| r: bytes.NewReader(encoded), | ||
| } | ||
|
|
||
| var decoded TestDoc | ||
| if err := stream.StreamJson(&decoded, true, ZstdCompression); err != nil { | ||
| t.Fatalf("failed to decode with ZstdCompression: %v", err) | ||
| } | ||
|
|
||
| // Compare | ||
| if decoded.Type != original.Type || decoded.Lang != original.Lang || decoded.Text != original.Text { | ||
| t.Errorf("StreamJson ZstdCompression roundtrip failed: got %+v, want %+v", decoded, original) | ||
| } |
There was a problem hiding this comment.
The new ZstdCompression tests only validate round-trip encode/decode using the same implementation, so they won’t fail if StreamJson accidentally switches back to a different zstd encoder configuration (the regression being fixed). To prevent that drift, add an assertion that StreamJson(ZstdCompression) produces the same encoded bytes as StreamJSONRawMessage(ZstdCompression) for the same JSON payload (including both null-terminated and non-null-terminated cases), or otherwise assert expected zstd frame/header characteristics.
| if err := binary.Write(s.w, binary.LittleEndian, uint32(len(b))); err != nil { | ||
| return fmt.Errorf("write error: %w", err) | ||
| } | ||
| w, err := zstd.NewWriter(s.w) | ||
| w, err := zstd.NewWriter(s.w, zstd.WithEncoderLevel(1)) | ||
| if err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
To avoid future zstd configuration drift between StreamJson and StreamJSONRawMessage (which caused this regression), consider factoring the zstd writer options into a shared helper/constant (e.g., a single function that returns a zstd.Writer with the required options) instead of repeating zstd.WithEncoderLevel(1) in multiple places. This makes it harder for the two methods to become inconsistent again.
Fixes the EULA download regression caused by inconsistent zstd compression encoder levels in the
StreamJsonmethod.Root Cause
The
DocumentSuccessmessage (which includes EULA documents) usesStreamJsonwithZstdCompressionmode. After the recent refactoring that introducedcore_stream.go, theStreamJsonmethod was creating a zstd writer with default settings, whileStreamJSONRawMessagewas usingzstd.WithEncoderLevel(1). This inconsistency caused the game client to fail decompression with "Unknown frame descriptor" error.Changes Made
StreamJsoninserver/evr/core_stream.goto usezstd.WithEncoderLevel(1)when compressing with ZstdCompression, ensuring consistency withStreamJSONRawMessageStreamJsonandStreamJSONRawMessagemethods inserver/evr/core_stream_test.goTesting
Impact
This fix ensures EULA documents are compressed using the correct zstd encoder level that the EchoVR game client expects, resolving the "Error performing zstd decompression: Unknown frame descriptor" issue.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.