Skip to content

Commit

Permalink
Add timeout to get Proxy Protocol header
Browse files Browse the repository at this point in the history
Configure go-proxyprotocol library to wait up to 100ms
for a Proxy Protocol header, before considering the incomming
connection as normal.

This requires a patched go-proxyproto library [1] and fixes #141 [2]

[1] armon/go-proxyproto#4
[2] #141
  • Loading branch information
keymon committed Jul 21, 2016
1 parent eb5871f commit 45c41d9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import (
var DrainTimeout = errors.New("router: Drain timeout")

const (
emitInterval = 1 * time.Second
emitInterval = 1 * time.Second
proxyProtocolHeaderTimeout = 100 * time.Millisecond
)

var noDeadline = time.Time{}
Expand Down Expand Up @@ -292,7 +293,10 @@ func (r *Router) serveHTTPS(server *http.Server, errChan chan error) error {

r.tlsListener = tlsListener
if r.config.EnablePROXY {
r.tlsListener = &proxyproto.Listener{Listener: tlsListener}
r.tlsListener = &proxyproto.Listener{
Listener: tlsListener,
ProxyHeaderTimeout: proxyProtocolHeaderTimeout,
}
}

r.logger.Info(fmt.Sprintf("Listening on %s", r.tlsListener.Addr()))
Expand All @@ -319,7 +323,10 @@ func (r *Router) serveHTTP(server *http.Server, errChan chan error) error {

r.listener = listener
if r.config.EnablePROXY {
r.listener = &proxyproto.Listener{Listener: listener}
r.listener = &proxyproto.Listener{
Listener: listener,
ProxyHeaderTimeout: proxyProtocolHeaderTimeout,
}
}

r.logger.Info(fmt.Sprintf("Listening on %s", r.listener.Addr()))
Expand Down

0 comments on commit 45c41d9

Please sign in to comment.