{"record":{"id":"6f7355f3abbb042b","repo":"nats-io/nats-server","slug":"compression-negotiation-error","errorCode":null,"errorMessage":"compression negotiation error","messagePattern":"compression negotiation error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/leafnode.go","lineNumber":3689,"sourceCode":"\tif err == nil &&\n\t\t(resp.StatusCode != 101 ||\n\t\t\t!strings.EqualFold(resp.Header.Get(\"Upgrade\"), \"websocket\") ||\n\t\t\t!strings.EqualFold(resp.Header.Get(\"Connection\"), \"upgrade\") ||\n\t\t\tresp.Header.Get(\"Sec-Websocket-Accept\") != wsAcceptKey(wsKey)) {\n\n\t\terr = fmt.Errorf(\"invalid websocket connection\")\n\t}\n\t// Check compression extension...\n\tif err == nil && c.ws.compress {\n\t\t// Check that not only permessage-deflate extension is present, but that\n\t\t// we also have server and client no context take over.\n\t\tsrvCompress, noCtxTakeover := wsPMCExtensionSupport(resp.Header, false)\n\n\t\t// If server does not support compression, then simply disable it in our side.\n\t\tif !srvCompress {\n\t\t\tc.ws.compress = false\n\t\t} else if !noCtxTakeover {\n\t\t\terr = fmt.Errorf(\"compression negotiation error\")\n\t\t}\n\t}\n\t// Same for no masking...\n\tif err == nil && noMasking {\n\t\t// Check if server accepts no masking\n\t\tif resp.Header.Get(wsNoMaskingHeader) != wsNoMaskingValue {\n\t\t\t// Nope, need to mask our writes as any client would do.\n\t\t\tc.ws.maskwrite = true\n\t\t}\n\t}\n\tif resp != nil {\n\t\tresp.Body.Close()\n\t}\n\tif err != nil {\n\t\treturn nil, ReadError, err\n\t}\n\tc.Debugf(\"Leafnode compression=%v masking=%v\", c.ws.compress, c.ws.maskwrite)\n","sourceCodeStart":3671,"sourceCodeEnd":3707,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/leafnode.go#L3671-L3707","documentation":"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.","triggerScenarios":"Thrown at server/leafnode.go:3689 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}