Skip to content

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

@hklcf

Description

@hklcf

Description

In protocol/hysteria2/realm_server.go:383, the error from json.Marshal is silently ignored:

data, _ := json.Marshal(ev.data)
fmt.Fprintf(w, "event: %s\ndata: %s\n\n", ev.kind, data)

Impact

If ev.data contains values that cannot be serialized by encoding/json (e.g., channels, functions, complex numbers, or cyclic data structures), the marshal will silently return an empty byte slice or incomplete JSON. The SSE stream will then send malformed data, and the client will receive corrupted or empty events with no indication of the error.

Location

protocol/hysteria2/realm_server.go:383

Suggested Fix

At minimum, log the error and skip the event:

data, err := json.Marshal(ev.data)
if err != nil {
    return
}
fmt.Fprintf(w, "event: %s\ndata: %s\n\n", ev.kind, data)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions