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

Method Shutdown

aibridge/bridge.go:389–421  ·  view source on GitHub ↗

Shutdown will attempt to gracefully shutdown. This entails waiting for all requests to complete, and shutting down the MCP server proxier. TODO: add tests.

(ctx context.Context)

Source from the content-addressed store, hash-verified

387// complete, and shutting down the MCP server proxier.
388// TODO: add tests.
389func (b *RequestBridge) Shutdown(ctx context.Context) error {
390 var err error
391 b.shutdownOnce.Do(func() {
392 // Prevent any new requests from being accepted.
393 close(b.closed)
394
395 // Wait for inflight requests to complete or context cancellation.
396 done := make(chan struct{})
397 go func() {
398 b.inflightWG.Wait()
399 close(done)
400 }()
401
402 select {
403 case <-ctx.Done():
404 // Cancel all inflight requests, if any are still running.
405 b.logger.Debug(ctx, "shutdown context canceled; canceling inflight requests", slog.Error(ctx.Err()))
406 b.inflightCancel()
407 <-done
408 err = ctx.Err()
409 case <-done:
410 }
411
412 if b.mcpProxy != nil {
413 // It's ok that we reuse the ctx here even if it's done, since the
414 // Shutdown method will just immediately use the more aggressive close
415 // since the ctx is already expired.
416 err = multierror.Append(err, b.mcpProxy.Shutdown(ctx))
417 }
418 })
419
420 return err
421}
422
423func (b *RequestBridge) InflightRequests() int32 {
424 return b.inflightReqs.Load()

Callers

nothing calls this directly

Calls 7

ErrMethod · 0.80
DoMethod · 0.65
WaitMethod · 0.65
ShutdownMethod · 0.65
DoneMethod · 0.45
ErrorMethod · 0.45
AppendMethod · 0.45

Tested by

no test coverage detected