lifecycle manages the lifecycle of the reconnecting pty. If the context ends the reconnecting pty will be closed.
(ctx context.Context, logger slog.Logger)
| 141 | // lifecycle manages the lifecycle of the reconnecting pty. If the context ends |
| 142 | // the reconnecting pty will be closed. |
| 143 | func (rpty *screenReconnectingPTY) lifecycle(ctx context.Context, logger slog.Logger) { |
| 144 | rpty.timer = time.AfterFunc(attachTimeout, func() { |
| 145 | rpty.Close(xerrors.New("reconnecting pty timeout")) |
| 146 | }) |
| 147 | |
| 148 | logger.Debug(ctx, "reconnecting pty ready") |
| 149 | rpty.state.setState(StateReady, nil) |
| 150 | |
| 151 | state, reasonErr := rpty.state.waitForStateOrContext(ctx, StateClosing) |
| 152 | if state < StateClosing { |
| 153 | // If we have not closed yet then the context is what unblocked us (which |
| 154 | // means the agent is shutting down) so move into the closing phase. |
| 155 | rpty.Close(reasonErr) |
| 156 | } |
| 157 | rpty.timer.Stop() |
| 158 | |
| 159 | // If the command errors that the session is already gone that is fine. |
| 160 | err := rpty.sendCommand(context.Background(), "quit", []string{"No screen session found"}) |
| 161 | if err != nil { |
| 162 | logger.Error(ctx, "close screen session", slog.Error(err)) |
| 163 | } |
| 164 | |
| 165 | logger.Info(ctx, "closed reconnecting pty") |
| 166 | rpty.state.setState(StateDone, reasonErr) |
| 167 | } |
| 168 | |
| 169 | func (rpty *screenReconnectingPTY) Attach(ctx context.Context, _ string, conn net.Conn, height, width uint16, logger slog.Logger) error { |
| 170 | logger.Info(ctx, "attach to reconnecting pty") |
no test coverage detected