{"record":{"id":"aa93a84a0ecb128f","repo":"ginuerzh/gost","slug":"deadline-not-supported","errorCode":null,"errorMessage":"deadline not supported","messagePattern":"deadline not supported","errorType":"error_code","errorClass":"net.OpError","httpStatus":null,"severity":"info","filePath":"dns.go","lineNumber":391,"sourceCode":"func (c *dnsServerConn) Close() error {\n\tselect {\n\tcase <-c.cclose:\n\tdefault:\n\t\tclose(c.cclose)\n\t}\n\treturn nil\n}\n\nfunc (c *dnsServerConn) LocalAddr() net.Addr {\n\treturn c.laddr\n}\n\nfunc (c *dnsServerConn) RemoteAddr() net.Addr {\n\treturn c.raddr\n}\n\nfunc (c *dnsServerConn) SetDeadline(t time.Time) error {\n\treturn &net.OpError{Op: \"set\", Net: \"dns\", Source: nil, Addr: nil, Err: errors.New(\"deadline not supported\")}\n}\n\nfunc (c *dnsServerConn) SetReadDeadline(t time.Time) error {\n\treturn &net.OpError{Op: \"set\", Net: \"dns\", Source: nil, Addr: nil, Err: errors.New(\"deadline not supported\")}\n}\n\nfunc (c *dnsServerConn) SetWriteDeadline(t time.Time) error {\n\treturn &net.OpError{Op: \"set\", Net: \"dns\", Source: nil, Addr: nil, Err: errors.New(\"deadline not supported\")}\n}\n\ntype dnsResponseWriter interface {\n\tio.Writer\n\tRemoteAddr() net.Addr\n}\n\ntype dohResponseWriter struct {\n\traddr net.Addr\n\thttp.ResponseWriter","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/dns.go#L373-L409","documentation":"dnsServerConn.SetDeadline unconditionally returns a *net.OpError wrapping 'deadline not supported' because DNS-over-HTTP/UDP virtual connections have no real socket deadlines to enforce. This is a deliberate capability limitation of the emulated conn, satisfying the net.Conn interface without implementing deadlines.","triggerScenarios":"Calling SetDeadline(t) on a conn obtained from the DNS listener's Accept(); any non-zero-time call immediately fails with this wrapped error.","commonSituations":"Wrapping the DNS conn in code that sets deadlines by default (e.g., io.LimitReader with timeout helpers, TLS handshake with deadline, copy loops with timeouts).","solutions":["Skip SetDeadline calls for DNS conns or guard them behind an interface check","Use context-based timeouts in the handler instead of conn deadlines","Ignore the error if deadlines are non-essential for the DNS exchange","Implement a real deadline mechanism (time.AfterFunc closing conn) if needed"],"exampleFix":"// before\nconn.SetDeadline(time.Now().Add(10 * time.Second))\n// after\ntype deadliner interface{ SetDeadline(time.Time) error }\nif d, ok := conn.(deadliner); ok {\n    if err := d.SetDeadline(time.Now().Add(10 * time.Second)); err != nil {\n        log.Logf(\"deadline unsupported: %s\", err) // DNS conn: use context timeout instead\n    }\n}","handlingStrategy":"type-guard","validationCode":"// detect deadline support before relying on it\ntype deadliner interface{ SetDeadline(time.Time) error }\n_, supportsDeadline := conn.(interface{ SupportsDeadline() bool }) // DNS conns do not","typeGuard":"var _ net.Conn = (*dnsServerConn)(nil) // known: deadlines unsupported\nfunc deadlinesSupported(c net.Conn) bool {\n    _, isDNSConn := c.(interface{ isDNSServerConnMarker() })\n    return !isDNSConn\n}","tryCatchPattern":"if err := conn.SetDeadline(time.Now().Add(d)); err != nil {\n    var opErr *net.OpError\n    if errors.As(err, &opErr) && opErr.Err.Error() == \"deadline not supported\" {\n        // fall back to context-based timeout\n        return nil\n    }\n    return err\n}","preventionTips":["Prefer context.Context timeouts over conn deadlines for DNS-backed conns","Wrap deadline setting in a capability check so TCP/UDP conns keep deadlines","Document that DNS virtual conns do not support deadlines in handler code","Ignore (don't fail on) the OpError wrapping 'deadline not supported'"],"tags":["dns","go","net-conn","deadline","unsupported"],"backgroundTag":"deadline-not-supported","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}