nats-io/nats-server · error
compression negotiation error
Error message
compression negotiation error
What it means
Placeholder error for the leaf-node WebSocket compression negotiation path: when the connection requested permessage-deflate, the server's response headers are inspected with wsPMCExtensionSupport and this branch fires when the negotiated extension parameters (e.g. server/client no-context-takeover) are not acceptable.
Source
Thrown at server/leafnode.go:3689
if err == nil &&
(resp.StatusCode != 101 ||
!strings.EqualFold(resp.Header.Get("Upgrade"), "websocket") ||
!strings.EqualFold(resp.Header.Get("Connection"), "upgrade") ||
resp.Header.Get("Sec-Websocket-Accept") != wsAcceptKey(wsKey)) {
err = fmt.Errorf("invalid websocket connection")
}
// Check compression extension...
if err == nil && c.ws.compress {
// Check that not only permessage-deflate extension is present, but that
// we also have server and client no context take over.
srvCompress, noCtxTakeover := wsPMCExtensionSupport(resp.Header, false)
// If server does not support compression, then simply disable it in our side.
if !srvCompress {
c.ws.compress = false
} else if !noCtxTakeover {
err = fmt.Errorf("compression negotiation error")
}
}
// Same for no masking...
if err == nil && noMasking {
// Check if server accepts no masking
if resp.Header.Get(wsNoMaskingHeader) != wsNoMaskingValue {
// Nope, need to mask our writes as any client would do.
c.ws.maskwrite = true
}
}
if resp != nil {
resp.Body.Close()
}
if err != nil {
return nil, ReadError, err
}
c.Debugf("Leafnode compression=%v masking=%v", c.ws.compress, c.ws.maskwrite)
View on GitHub (pinned to 3a66a489d2)
Solutions
- Disable WebSocket compression on the leaf node connection if the peer does not negotiate permessage-deflate correctly
- Upgrade the peer NATS server so both sides agree on no-context-takeover parameters
- Inspect the 101 response headers to see which compression parameter mismatched
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at server/leafnode.go:3689 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02).
Data as JSON: /api/errors/6f7355f3abbb042b.
Report an issue: GitHub.