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

Method doAttach

agent/reconnectingpty/buffered.go:215–232  ·  view source on GitHub ↗

doAttach adds the connection to the map and replays the buffer. It exists separately only for convenience to defer the mutex unlock which is not possible in Attach since it blocks.

(connID string, conn net.Conn)

Source from the content-addressed store, hash-verified

213// separately only for convenience to defer the mutex unlock which is not
214// possible in Attach since it blocks.
215func (rpty *bufferedReconnectingPTY) doAttach(connID string, conn net.Conn) error {
216 rpty.state.cond.L.Lock()
217 defer rpty.state.cond.L.Unlock()
218
219 // Write any previously stored data for the TTY. Since the command might be
220 // short-lived and have already exited, make sure we always at least output
221 // the buffer before returning, mostly just so tests pass.
222 prevBuf := slices.Clone(rpty.circularBuffer.Bytes())
223 _, err := conn.Write(prevBuf)
224 if err != nil {
225 rpty.metrics.WithLabelValues("write").Add(1)
226 return xerrors.Errorf("write buffer to conn: %w", err)
227 }
228
229 rpty.activeConns[connID] = conn
230
231 return nil
232}
233
234func (rpty *bufferedReconnectingPTY) Wait() {
235 _, _ = rpty.state.waitForState(StateClosing)

Callers 1

AttachMethod · 0.95

Calls 8

WithLabelValuesMethod · 0.80
WriteMethod · 0.65
AddMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
CloneMethod · 0.45
BytesMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected