mirror of https://github.com/coder/coder.git
feat: add logging for forwarded TCP connections
part of #7963 log TCP connections as they are forwarded by gVisor
This commit is contained in:
parent
791144ddfd
commit
236e84c4d6
|
@ -943,7 +943,8 @@ func (c *Conn) DialContextUDP(ctx context.Context, ipp netip.AddrPort) (*gonet.U
|
|||
return c.netStack.DialContextUDP(ctx, ipp)
|
||||
}
|
||||
|
||||
func (c *Conn) forwardTCP(_, dst netip.AddrPort) (handler func(net.Conn), opts []tcpip.SettableSocketOption, intercept bool) {
|
||||
func (c *Conn) forwardTCP(src, dst netip.AddrPort) (handler func(net.Conn), opts []tcpip.SettableSocketOption, intercept bool) {
|
||||
logger := c.logger.Named("tcp").With(slog.F("src", src.String()), slog.F("dst", dst.String()))
|
||||
c.mutex.Lock()
|
||||
ln, ok := c.listeners[listenKey{"tcp", "", fmt.Sprint(dst.Port())}]
|
||||
c.mutex.Unlock()
|
||||
|
@ -961,10 +962,14 @@ func (c *Conn) forwardTCP(_, dst netip.AddrPort) (handler func(net.Conn), opts [
|
|||
defer t.Stop()
|
||||
select {
|
||||
case ln.conn <- conn:
|
||||
logger.Info(context.Background(), "accepted connection")
|
||||
return
|
||||
case <-ln.closed:
|
||||
logger.Info(context.Background(), "listener closed; closing connection")
|
||||
case <-c.closed:
|
||||
logger.Info(context.Background(), "tailnet closed; closing connection")
|
||||
case <-t.C:
|
||||
logger.Info(context.Background(), "listener timed out accepting; closing connection")
|
||||
}
|
||||
_ = conn.Close()
|
||||
}, opts, true
|
||||
|
|
Loading…
Reference in New Issue