Skip to content

fix(hysteria2): check json.Marshal error in SSE event stream#4168

Open
hklcf wants to merge 1 commit into
SagerNet:testingfrom
hklcf:fix/hysteria2-jsonmarshal
Open

fix(hysteria2): check json.Marshal error in SSE event stream#4168
hklcf wants to merge 1 commit into
SagerNet:testingfrom
hklcf:fix/hysteria2-jsonmarshal

Conversation

@hklcf
Copy link
Copy Markdown

@hklcf hklcf commented May 23, 2026

Description

In \protocol/hysteria2/realm_server.go:383, the error from \json.Marshal\ is silently discarded with \data, _ := json.Marshal(ev.data). If \ev.data\ contains values that cannot be serialized (e.g., cyclic structures), the SSE stream sends empty data with no error logged.

Fix

Check the error from \json.Marshal, log it, and skip the event to avoid sending corrupted data.

Related Issue

Fixes #4163

If ev.data contains values that cannot be serialized by encoding/json,
the marshal would silently return empty data, corrupting the SSE stream.
Check the error and log it, skipping the event on failure.

Fixes SagerNet#4163
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.

Bug: json.Marshal error ignored in hysteria2 realm_server SSE event stream

1 participant