Documentation
¶
Overview ¶
Package connadmit admits connections to an HTTP listener: up to a cap they are served, past it they wait in a bounded FIFO for a slot for at most a fixed time, and the rest are answered with a 503 and closed. It accepts from the kernel continuously, so a connection flood never sits unanswered in the accept backlog, where SYN drops turn into silent client retransmits.
Scope: the listener wrapper, the connection it hands to Serve, and an http.Server.ConnState hook that tracks idle keep-alive connections so one can be closed for a queued connection. Out of scope: request-level admission (in-flight caps and load shedding live above it), TLS, and shaping the refusal per API: the conn layer has not routed the request, so every refusal carries the one response it was given.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// MaxConns is the most connections handed to Serve at once; must be positive.
MaxConns int
// QueueSize is the most connections waiting for a slot; 0 refuses every connection past MaxConns.
QueueSize int
// QueueTimeout is how long a connection waits for a slot before it is refused.
QueueTimeout time.Duration
// Body is the JSON body of the 503 refusal.
Body []byte
// RetryAfter is the refusal's Retry-After value.
RetryAfter string
// Header holds extra headers of the refusal.
Header http.Header
// CloseIdle closes the oldest keep-alive connection idle for minIdleAge when a connection is queued, and needs ConnState set on the server. Off, a client's spare keep-alive connections stay open: closing them makes it dial again on its next burst, which feeds a reconnect herd.
CloseIdle bool
}
Config sets the listener's limits and its refusal.
type Conn ¶
Conn is a connection holding one of the listener's slots until it is closed.
func (*Conn) CloseWrite ¶
CloseWrite half-closes the connection when the inner one supports it, which net/http uses to avoid resetting a closing connection.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener wraps a net.Listener with connection admission. Accept returns *Conn values.
func New ¶
New starts accepting from inner. The caller passes the Listener to http.Server.Serve and sets the server's ConnState to l.ConnState.
func (*Listener) Accept ¶
Accept returns the next connection holding a slot. After Close, or once the inner listener fails, it returns the inner listener's error.