Skip to content

Commit

Permalink
Fix wrong frontend address in log / prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
setaou committed Sep 1, 2023
1 parent d84c843 commit 64331c4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions proxy/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ func (p *ProxyTCP) pipe(input net.Conn, output net.Conn, done chan bool, input_t
}

func (p *ProxyTCP) handle_connection(conn_front net.Conn) {
frontend_address := conn_front.RemoteAddr().String()
frontend_address := conn_front.LocalAddr().String()
peer_address := conn_front.RemoteAddr().String()

defer p.connections_wg.Done()
defer conn_front.Close()
defer p.log.Debug().Str("peer", frontend_address).Msg("Closing Frontend connection")
defer p.log.Debug().Str("peer", peer_address).Msg("Closing Frontend connection")

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -204,14 +205,14 @@ func (p *ProxyTCP) handle_connection(conn_front net.Conn) {
case <-ctx.Done():
return
case <-p.ctx.Done():
p.log.Debug().Str("peer", frontend_address).Msg("Frontend closed, waiting for connection to end.")
p.log.Debug().Str("peer", peer_address).Msg("Frontend closed, waiting for connection to end.")
}

select {
case <-ctx.Done():
return
case <-time.After(p.close_timeout):
p.log.Warn().Str("peer", frontend_address).Msg("Timeout reached, force closing connection.")
p.log.Warn().Str("peer", peer_address).Msg("Timeout reached, force closing connection.")
cancel()
}
}()
Expand All @@ -227,7 +228,7 @@ func (p *ProxyTCP) handle_connection(conn_front net.Conn) {
// Error handler
defer func() {
if r := recover(); r != nil {
p.log.Error().Str("peer", frontend_address).Err(misc.EnsureError(r)).Msg("Error while processing connection")
p.log.Error().Str("peer", peer_address).Err(misc.EnsureError(r)).Msg("Error while processing connection")
// Prometheus
metrics.FeCnxErrors.WithLabelValues(frontend_address).Inc()
}
Expand Down

0 comments on commit 64331c4

Please sign in to comment.