vitessio/vitess · error

can't call SetWriteDeadline for ConnWithTimeouts

Error message

can't call SetWriteDeadline for ConnWithTimeouts

What it means

SetWriteDeadline on ConnWithTimeouts panics by design: write timeouts are enforced inside Write using the configured write timeout, so per-call deadline APIs are unsupported. This stub turns a semantic misuse into an immediate, loud failure.

Source

Thrown at go/netutil/conn.go:71

	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 plain net.Conn for deadline-based consumers.
  2. Tune the write timeout supplied to WithTimeouts to cover slow-writer cases.
  3. Refactor to a deadline-based conn (drop WithTimeouts) if deadlines are the actual requirement.

Example fix

// before
conn.SetWriteDeadline(time.Now().Add(10 * time.Second)) // panics
// after
// configure once:
conn := netutil.ConnWithTimeouts{Conn: raw, WriteTimeout: 10 * time.Second}
Defensive patterns

Strategy: type-guard

Validate before calling

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

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("SetWriteDeadline unsupported: %v", r) } }()

Prevention

When it happens

Trigger: Calling SetWriteDeadline directly, or giving the conn to libraries that set write deadlines (TLS record writing, HTTP response writing, chunked proxy relays).

Common situations: Writing proxy/server code that periodically refreshes write deadlines for slow clients; integrating with frameworks assuming standard net.Conn deadline semantics.

Understand the failure class

Related errors


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