vitessio/vitess · error

can't call SetReadDeadline for ConnWithTimeouts

Error message

can't call SetReadDeadline for ConnWithTimeouts

What it means

Like SetDeadline, SetReadDeadline is intentionally unimplemented on ConnWithTimeouts: read timeouts are applied per Read call via the configured timeouts, so a panicking stub enforces the contract. Any code path calling SetReadDeadline on this wrapper crashes.

Source

Thrown at go/netutil/conn.go:66

// Write sets a write deadline and delegates to conn.Write
func (c ConnWithTimeouts) Write(b []byte) (int, error) {
	if c.writeTimeout == 0 {
		return c.Conn.Write(b)
	}
	if err := c.Conn.SetWriteDeadline(time.Now().Add(c.writeTimeout)); err != nil {
		return 0, err
	}
	return c.Conn.Write(b)
}

// SetDeadline implements the Conn SetDeadline method.
func (c ConnWithTimeouts) SetDeadline(t time.Time) error {
	panic("can't call SetDeadline for ConnWithTimeouts")
}

// SetReadDeadline implements the Conn SetReadDeadline method.
func (c ConnWithTimeouts) SetReadDeadline(t time.Time) error {
	panic("can't call SetReadDeadline for ConnWithTimeouts")
}

// SetWriteDeadline implements the Conn SetWriteDeadline method.
func (c ConnWithTimeouts) SetWriteDeadline(t time.Time) error {
	panic("can't call SetWriteDeadline for ConnWithTimeouts")
}

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Pass the raw net.Conn to deadline-sensitive consumers.
  2. Encode read timeout requirements in the WithTimeouts configuration instead.
  3. Use a plain conn plus explicit SetReadDeadline if per-connection deadlines are required.

Example fix

// before
conn.SetReadDeadline(time.Now().Add(5 * time.Second)) // panics on ConnWithTimeouts
// after
rawConn.SetReadDeadline(time.Now().Add(5 * time.Second))
Defensive patterns

Strategy: type-guard

Validate before calling

if _, isTimeouts := conn.(netutil.ConnWithTimeouts); isTimeouts {
    return errors.New("use per-call timeouts, not SetReadDeadline")
}

Type guard

func isConnWithTimeouts(c net.Conn) bool {
    _, ok := c.(netutil.ConnWithTimeouts)
    return ok
}

Try / catch

defer func() { if r := recover(); r != nil { err = fmt.Errorf("SetReadDeadline unsupported: %v", r) } }()

Prevention

When it happens

Trigger: Handing ConnWithTimeouts to code that sets read deadlines before reads — TLS handshakes, HTTP server conns (http.ConnState handlers), bufio-based protocols, or net/http.Serve wrapping.

Common situations: Proxying a timeout-configured conn into net/http or crypto/tls which unconditionally call SetReadDeadline; refactoring code that previously used plain conns.

Understand the failure class

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/2b2332bdc11a0b78. Report an issue: GitHub.