diff --git a/agent/agent_test.go b/agent/agent_test.go index d4c857dc39..ca00180767 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -1807,11 +1807,12 @@ func TestAgent_ReconnectingPTY(t *testing.T) { //nolint:dogsled conn, agentClient, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0) + idConnectionReport := uuid.New() id := uuid.New() // Test that the connection is reported. This must be tested in the // first connection because we care about verifying all of these. - netConn0, err := conn.ReconnectingPTY(ctx, id, 80, 80, "bash --norc") + netConn0, err := conn.ReconnectingPTY(ctx, idConnectionReport, 80, 80, "bash --norc") require.NoError(t, err) _ = netConn0.Close() assertConnectionReport(t, agentClient, proto.Connection_RECONNECTING_PTY, 0, "") diff --git a/agent/reconnectingpty/screen.go b/agent/reconnectingpty/screen.go index 04e1861ead..ffab2f7d5b 100644 --- a/agent/reconnectingpty/screen.go +++ b/agent/reconnectingpty/screen.go @@ -25,6 +25,7 @@ import ( // screenReconnectingPTY provides a reconnectable PTY via `screen`. type screenReconnectingPTY struct { + logger slog.Logger execer agentexec.Execer command *pty.Cmd @@ -62,6 +63,7 @@ type screenReconnectingPTY struct { // own which causes it to spawn with the specified size. func newScreen(ctx context.Context, logger slog.Logger, execer agentexec.Execer, cmd *pty.Cmd, options *Options) *screenReconnectingPTY { rpty := &screenReconnectingPTY{ + logger: logger, execer: execer, command: cmd, metrics: options.Metrics, @@ -173,6 +175,7 @@ func (rpty *screenReconnectingPTY) Attach(ctx context.Context, _ string, conn ne ptty, process, err := rpty.doAttach(ctx, conn, height, width, logger) if err != nil { + logger.Debug(ctx, "unable to attach to screen reconnecting pty", slog.Error(err)) if errors.Is(err, context.Canceled) { // Likely the process was too short-lived and canceled the version command. // TODO: Is it worth distinguishing between that and a cancel from the @@ -182,6 +185,7 @@ func (rpty *screenReconnectingPTY) Attach(ctx context.Context, _ string, conn ne } return err } + logger.Debug(ctx, "attached to screen reconnecting pty") defer func() { // Log only for debugging since the process might have already exited on its @@ -403,6 +407,7 @@ func (rpty *screenReconnectingPTY) Wait() { } func (rpty *screenReconnectingPTY) Close(err error) { + rpty.logger.Debug(context.Background(), "closing screen reconnecting pty", slog.Error(err)) // The closing state change will be handled by the lifecycle. rpty.state.setState(StateClosing, err) }