{"record":{"id":"dcae745c18e201aa","repo":"ginuerzh/gost","slug":"deadline-not-supported-dcae74","errorCode":null,"errorMessage":"deadline not supported","messagePattern":"deadline not supported","errorType":"error_code","errorClass":"net.OpError","httpStatus":null,"severity":"info","filePath":"http2.go","lineNumber":871,"sourceCode":"\tif rc, ok := c.r.(io.Closer); ok {\n\t\terr = rc.Close()\n\t}\n\tif w, ok := c.w.(io.Closer); ok {\n\t\terr = w.Close()\n\t}\n\treturn\n}\n\nfunc (c *http2Conn) LocalAddr() net.Addr {\n\treturn c.localAddr\n}\n\nfunc (c *http2Conn) RemoteAddr() net.Addr {\n\treturn c.remoteAddr\n}\n\nfunc (c *http2Conn) SetDeadline(t time.Time) error {\n\treturn &net.OpError{Op: \"set\", Net: \"http2\", Source: nil, Addr: nil, Err: errors.New(\"deadline not supported\")}\n}\n\nfunc (c *http2Conn) SetReadDeadline(t time.Time) error {\n\treturn &net.OpError{Op: \"set\", Net: \"http2\", Source: nil, Addr: nil, Err: errors.New(\"deadline not supported\")}\n}\n\nfunc (c *http2Conn) SetWriteDeadline(t time.Time) error {\n\treturn &net.OpError{Op: \"set\", Net: \"http2\", Source: nil, Addr: nil, Err: errors.New(\"deadline not supported\")}\n}\n\n// a dummy HTTP2 server conn used by HTTP2 handler\ntype http2ServerConn struct {\n\tr      *http.Request\n\tw      http.ResponseWriter\n\tclosed chan struct{}\n}\n\nfunc (c *http2ServerConn) Read(b []byte) (n int, err error) {","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/http2.go#L853-L889","documentation":"http2Conn does not support deadlines: SetDeadline always returns a *net.OpError wrapping \"deadline not supported\". HTTP/2 multiplexed streams in this library provide no mechanism to set an overall I/O deadline on the wrapped conn, so the net.Conn deadline API is stubbed out.","triggerScenarios":"Calling SetDeadline(t) on a conn obtained from an http2 listener/dialer, typically via generic net.Conn timeout code (conn.SetDeadline(time.Now().Add(5*time.Second))) or code paths like tls.Server(conn) that set handshake deadlines.","commonSituations":"Dropping an http2Conn into middleware that uniformly sets deadlines on all net.Conn values; wrapping in TLS or proxy code that relies on SetDeadline; porting code written for TCP conns to http2 conns.","solutions":["Skip SetDeadline calls when the conn is an http2Conn (type-assert or feature-detect) and rely on context cancellation of the underlying HTTP/2 request instead.","Implement read/write timeouts at the application layer using goroutines + timers around Read/Write.","Use the h2/tls transport's context or Close() as the timeout mechanism instead of deadlines.","Check err from SetDeadline and log-or-ignore if it is the unsupported-deadline OpError rather than treating it as fatal."],"exampleFix":"// before\nconn.SetDeadline(time.Now().Add(10 * time.Second)) // returns error\n// after\nif dc, ok := conn.(interface{ SetDeadline(time.Time) error }); ok {\n    if err := dc.SetDeadline(time.Now().Add(10 * time.Second)); err != nil {\n        // http2 conn: use ctx cancellation instead\n        ctx, cancel = context.WithTimeout(ctx, 10*time.Second)\n    }\n}","handlingStrategy":"type-guard","validationCode":"// detect deadline support before calling\ncanDeadline := func(c net.Conn) bool {\n    type dl interface{ SetDeadline(time.Time) error }\n    _, ok := c.(dl)\n    return ok // http2Conn still implements it but always errors; prefer context timeouts\n}","typeGuard":"func supportsDeadline(c net.Conn) bool {\n    var opErr *net.OpError\n    err := c.SetDeadline(time.Now())\n    return !(err != nil && errors.As(err, &opErr) && opErr.Net == \"http2\")\n}","tryCatchPattern":"if err := conn.SetDeadline(t); err != nil {\n    var oe *net.OpError\n    if errors.As(err, &oe) && oe.Net == \"http2\" {\n        // fall back to context-based timeout\n        ctx, cancel := context.WithTimeout(ctx, d)\n        defer cancel()\n    } else {\n        return err\n    }\n}","preventionTips":["Use context timeouts for HTTP/2 stream operations instead of conn deadlines.","Keep timeout logic per-conn-type instead of a single generic path.","Remember TLS wrappers call SetDeadline during handshake — supply conns that support it."],"tags":["http2","deadline","net-conn","unsupported-operation"],"backgroundTag":"deadline-not-supported","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}