{"record":{"id":"4e4cfbee91a757e7","repo":"vitessio/vitess","slug":"can-t-call-setdeadline-for-connwithtimeouts","errorCode":null,"errorMessage":"can't call SetDeadline for ConnWithTimeouts","messagePattern":"can't call SetDeadline for ConnWithTimeouts","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/netutil/conn.go","lineNumber":61,"sourceCode":"\t\treturn 0, err\n\t}\n\treturn c.Conn.Read(b)\n}\n\n// Write sets a write deadline and delegates to conn.Write\nfunc (c ConnWithTimeouts) Write(b []byte) (int, error) {\n\tif c.writeTimeout == 0 {\n\t\treturn c.Conn.Write(b)\n\t}\n\tif err := c.Conn.SetWriteDeadline(time.Now().Add(c.writeTimeout)); err != nil {\n\t\treturn 0, err\n\t}\n\treturn c.Conn.Write(b)\n}\n\n// SetDeadline implements the Conn SetDeadline method.\nfunc (c ConnWithTimeouts) SetDeadline(t time.Time) error {\n\tpanic(\"can't call SetDeadline for ConnWithTimeouts\")\n}\n\n// SetReadDeadline implements the Conn SetReadDeadline method.\nfunc (c ConnWithTimeouts) SetReadDeadline(t time.Time) error {\n\tpanic(\"can't call SetReadDeadline for ConnWithTimeouts\")\n}\n\n// SetWriteDeadline implements the Conn SetWriteDeadline method.\nfunc (c ConnWithTimeouts) SetWriteDeadline(t time.Time) error {\n\tpanic(\"can't call SetWriteDeadline for ConnWithTimeouts\")\n}\n","sourceCodeStart":43,"sourceCodeEnd":73,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/netutil/conn.go#L43-L73","documentation":"ConnWithTimeouts implements deadline-free reads/writes using per-call timeouts; it cannot honor net.Conn's SetDeadline, so the method deliberately panics. Calling it is a programming error: the wrapper's whole contract is that timeouts are set per operation, not via deadlines.","triggerScenarios":"Passing a ConnWithTimeouts to code that calls SetDeadline — e.g. wrapping it in a net.Conn-based library (tls.Server/Client handshake code, http.Transport, proxy code) that sets deadlines before I/O.","commonSituations":"Using conn.WithTimeouts or netutil's timeout conn with TLS libraries or HTTP clients that internally call SetDeadline; generic code that treats all net.Conn uniformly.","solutions":["Use the underlying raw net.Conn when the consumer requires SetDeadline support.","Configure the timeout values passed to WithTimeouts instead of relying on deadlines.","Wrap the conn in an adapter that emulates deadlines if deadline semantics are truly needed."],"exampleFix":"// before\ntlsConn := tls.Client(connWithTimeouts, cfg) // panics: TLS calls SetDeadline\n// after\ntlsConn := tls.Client(rawConn, cfg) // use the plain net.Conn","handlingStrategy":"type-guard","validationCode":"// ensure the consumer doesn't require deadlines:\nif _, ok := conn.(interface{ SetDeadline(time.Time) error }); ok && isConnWithTimeouts(conn) {\n    return errors.New(\"conn cannot support deadlines\")\n}","typeGuard":"func supportsDeadlines(c net.Conn) bool {\n    type deadlineConn interface{ SetDeadline(time.Time) error }\n    _, ok := c.(ConnWithTimeouts)\n    return !ok // ConnWithTimeouts panics on deadlines\n}","tryCatchPattern":"defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"SetDeadline unsupported: %v\", r) } }()","preventionTips":["Never wrap ConnWithTimeouts in crypto/tls or net/http consumers.","Configure timeouts via WithTimeouts parameters, not deadlines.","Document in wrappers that deadline methods are unsupported."],"tags":["network","deadline","panic","netutil"],"backgroundTag":"unsupported-deadline-operation","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}