MCPcopy Index your code
hub / github.com/coder/coder / lifecycle

Method lifecycle

agent/reconnectingpty/screen.go:143–167  ·  view source on GitHub ↗

lifecycle manages the lifecycle of the reconnecting pty. If the context ends the reconnecting pty will be closed.

(ctx context.Context, logger slog.Logger)

Source from the content-addressed store, hash-verified

141// lifecycle manages the lifecycle of the reconnecting pty. If the context ends
142// the reconnecting pty will be closed.
143func (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
169func (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")

Callers 1

newScreenFunction · 0.95

Calls 8

CloseMethod · 0.95
sendCommandMethod · 0.95
setStateMethod · 0.80
waitForStateOrContextMethod · 0.80
NewMethod · 0.65
StopMethod · 0.65
ErrorMethod · 0.45
InfoMethod · 0.45

Tested by

no test coverage detected