Differentiate UDP stream and TCP connection in logs
This commit is contained in:
parent
479878503d
commit
38f5024ed0
2 changed files with 11 additions and 11 deletions
|
@ -48,14 +48,14 @@ func NewProxy(address string, terminationDelay time.Duration, proxyProtocol *dyn
|
||||||
|
|
||||||
// ServeTCP forwards the connection to a service.
|
// ServeTCP forwards the connection to a service.
|
||||||
func (p *Proxy) ServeTCP(conn WriteCloser) {
|
func (p *Proxy) ServeTCP(conn WriteCloser) {
|
||||||
log.WithoutContext().Debugf("Handling connection from %s to %s", conn.RemoteAddr(), p.address)
|
log.WithoutContext().Debugf("Handling TCP connection from %s to %s", conn.RemoteAddr(), p.address)
|
||||||
|
|
||||||
// needed because of e.g. server.trackedConnection
|
// needed because of e.g. server.trackedConnection
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
connBackend, err := p.dialBackend()
|
connBackend, err := p.dialBackend()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithoutContext().Errorf("Error while connecting to backend: %v", err)
|
log.WithoutContext().Errorf("Error while dialing backend: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ func (p *Proxy) ServeTCP(conn WriteCloser) {
|
||||||
if p.proxyProtocol != nil && p.proxyProtocol.Version > 0 && p.proxyProtocol.Version < 3 {
|
if p.proxyProtocol != nil && p.proxyProtocol.Version > 0 && p.proxyProtocol.Version < 3 {
|
||||||
header := proxyproto.HeaderProxyFromAddrs(byte(p.proxyProtocol.Version), conn.RemoteAddr(), conn.LocalAddr())
|
header := proxyproto.HeaderProxyFromAddrs(byte(p.proxyProtocol.Version), conn.RemoteAddr(), conn.LocalAddr())
|
||||||
if _, err := header.WriteTo(connBackend); err != nil {
|
if _, err := header.WriteTo(connBackend); err != nil {
|
||||||
log.WithoutContext().Errorf("Error while writing proxy protocol headers to backend connection: %v", err)
|
log.WithoutContext().Errorf("Error while writing TCP proxy protocol headers to backend connection: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,9 +80,9 @@ func (p *Proxy) ServeTCP(conn WriteCloser) {
|
||||||
// This allows to not report an RST packet sent by the peer as an error,
|
// This allows to not report an RST packet sent by the peer as an error,
|
||||||
// as it is an abrupt but possible end for the TCP session
|
// as it is an abrupt but possible end for the TCP session
|
||||||
if isReadConnResetError(err) {
|
if isReadConnResetError(err) {
|
||||||
log.WithoutContext().Debugf("Error during connection: %v", err)
|
log.WithoutContext().Debugf("Error while handling TCP connection: %v", err)
|
||||||
} else {
|
} else {
|
||||||
log.WithoutContext().Errorf("Error during connection: %v", err)
|
log.WithoutContext().Errorf("Error while handling TCP connection: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ func (p Proxy) connCopy(dst, src WriteCloser, errCh chan error) {
|
||||||
// In that case, logging the error is superfluous,
|
// In that case, logging the error is superfluous,
|
||||||
// as in the first place we should not have needed to call CloseWrite.
|
// as in the first place we should not have needed to call CloseWrite.
|
||||||
if !isSocketNotConnectedError(errClose) {
|
if !isSocketNotConnectedError(errClose) {
|
||||||
log.WithoutContext().Debugf("Error while terminating connection: %v", errClose)
|
log.WithoutContext().Debugf("Error while terminating TCP connection: %v", errClose)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -128,7 +128,7 @@ func (p Proxy) connCopy(dst, src WriteCloser, errCh chan error) {
|
||||||
if p.terminationDelay >= 0 {
|
if p.terminationDelay >= 0 {
|
||||||
err := dst.SetReadDeadline(time.Now().Add(p.terminationDelay))
|
err := dst.SetReadDeadline(time.Now().Add(p.terminationDelay))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithoutContext().Debugf("Error while setting deadline: %v", err)
|
log.WithoutContext().Debugf("Error while setting TCP connection deadline: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,14 @@ func NewProxy(address string) (*Proxy, error) {
|
||||||
|
|
||||||
// ServeUDP implements the Handler interface.
|
// ServeUDP implements the Handler interface.
|
||||||
func (p *Proxy) ServeUDP(conn *Conn) {
|
func (p *Proxy) ServeUDP(conn *Conn) {
|
||||||
log.WithoutContext().Debugf("Handling connection from %s to %s", conn.rAddr, p.target)
|
log.WithoutContext().Debugf("Handling UDP stream from %s to %s", conn.rAddr, p.target)
|
||||||
|
|
||||||
// needed because of e.g. server.trackedConnection
|
// needed because of e.g. server.trackedConnection
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
connBackend, err := net.Dial("udp", p.target)
|
connBackend, err := net.Dial("udp", p.target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithoutContext().Errorf("Error while connecting to backend: %v", err)
|
log.WithoutContext().Errorf("Error while dialing backend: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ func (p *Proxy) ServeUDP(conn *Conn) {
|
||||||
|
|
||||||
err = <-errChan
|
err = <-errChan
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithoutContext().Errorf("Error while serving UDP: %v", err)
|
log.WithoutContext().Errorf("Error while handling UDP stream: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
<-errChan
|
<-errChan
|
||||||
|
@ -55,6 +55,6 @@ func connCopy(dst io.WriteCloser, src io.Reader, errCh chan error) {
|
||||||
errCh <- err
|
errCh <- err
|
||||||
|
|
||||||
if err := dst.Close(); err != nil {
|
if err := dst.Close(); err != nil {
|
||||||
log.WithoutContext().Debugf("Error while terminating connection: %v", err)
|
log.WithoutContext().Debugf("Error while terminating UDP stream: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue