vitessio/vitess · error

can't call SetDeadline for ConnWithTimeouts

Error message

can't call SetDeadline for ConnWithTimeouts

What it means

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.

Source

Thrown at go/netutil/conn.go:61

		return 0, err
	}
	return c.Conn.Read(b)
}

// 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. Use the underlying raw net.Conn when the consumer requires SetDeadline support.
  2. Configure the timeout values passed to WithTimeouts instead of relying on deadlines.
  3. Wrap the conn in an adapter that emulates deadlines if deadline semantics are truly needed.

Example fix

// before
tlsConn := tls.Client(connWithTimeouts, cfg) // panics: TLS calls SetDeadline
// after
tlsConn := tls.Client(rawConn, cfg) // use the plain net.Conn
Defensive patterns

Strategy: type-guard

Validate before calling

// ensure the consumer doesn't require deadlines:
if _, ok := conn.(interface{ SetDeadline(time.Time) error }); ok && isConnWithTimeouts(conn) {
    return errors.New("conn cannot support deadlines")
}

Type guard

func supportsDeadlines(c net.Conn) bool {
    type deadlineConn interface{ SetDeadline(time.Time) error }
    _, ok := c.(ConnWithTimeouts)
    return !ok // ConnWithTimeouts panics on deadlines
}

Try / catch

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

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


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