Skip to content

Commit 56ca7ac

Browse files
committed
Fix incorrect logger context on reconnecting PTY
Since we used the same var all I did with my other change was use the same logger anyway. Now it will not have the connection ID, which is correct since the pty is not tied to a single connection.
1 parent 7a8ec2e commit 56ca7ac

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

agent/agent.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,8 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, logger slog.Logger, m
10711071
defer a.connCountReconnectingPTY.Add(-1)
10721072

10731073
connectionID := uuid.NewString()
1074-
logger = logger.With(slog.F("message_id", msg.ID), slog.F("connection_id", connectionID))
1075-
logger.Debug(ctx, "starting handler")
1074+
connLogger := logger.With(slog.F("message_id", msg.ID), slog.F("connection_id", connectionID))
1075+
connLogger.Debug(ctx, "starting handler")
10761076

10771077
defer func() {
10781078
if err := retErr; err != nil {
@@ -1083,12 +1083,12 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, logger slog.Logger, m
10831083
// If the agent is closed, we don't want to
10841084
// log this as an error since it's expected.
10851085
if closed {
1086-
logger.Debug(ctx, "reconnecting pty failed with attach error (agent closed)", slog.Error(err))
1086+
connLogger.Debug(ctx, "reconnecting pty failed with attach error (agent closed)", slog.Error(err))
10871087
} else {
1088-
logger.Error(ctx, "reconnecting pty failed with attach error", slog.Error(err))
1088+
connLogger.Error(ctx, "reconnecting pty failed with attach error", slog.Error(err))
10891089
}
10901090
}
1091-
logger.Debug(ctx, "reconnecting pty connection closed")
1091+
connLogger.Debug(ctx, "reconnecting pty connection closed")
10921092
}()
10931093

10941094
var rpty reconnectingpty.ReconnectingPTY
@@ -1097,7 +1097,7 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, logger slog.Logger, m
10971097
waitReady, ok := a.reconnectingPTYs.LoadOrStore(msg.ID, sendConnected)
10981098
if ok {
10991099
close(sendConnected) // Unused.
1100-
logger.Debug(ctx, "connecting to existing reconnecting pty")
1100+
connLogger.Debug(ctx, "connecting to existing reconnecting pty")
11011101
c, ok := waitReady.(chan reconnectingpty.ReconnectingPTY)
11021102
if !ok {
11031103
return xerrors.Errorf("found invalid type in reconnecting pty map: %T", waitReady)
@@ -1108,7 +1108,7 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, logger slog.Logger, m
11081108
}
11091109
c <- rpty // Put it back for the next reconnect.
11101110
} else {
1111-
logger.Debug(ctx, "creating new reconnecting pty")
1111+
connLogger.Debug(ctx, "creating new reconnecting pty")
11121112

11131113
connected := false
11141114
defer func() {
@@ -1141,7 +1141,7 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, logger slog.Logger, m
11411141
connected = true
11421142
sendConnected <- rpty
11431143
}
1144-
return rpty.Attach(ctx, connectionID, conn, msg.Height, msg.Width, logger)
1144+
return rpty.Attach(ctx, connectionID, conn, msg.Height, msg.Width, connLogger)
11451145
}
11461146

11471147
// startReportingConnectionStats runs the connection stats reporting goroutine.

0 commit comments

Comments
 (0)