MCPcopy Create free account
hub / github.com/github/copilot-sdk / ForceStop

Method ForceStop

go/client.go:547–594  ·  view source on GitHub ↗

ForceStop forcefully stops the CLI server without graceful cleanup. Use this when [Client.Stop] fails or takes too long. This method: - Clears all sessions immediately without destroying them - Force closes the connection - Kills the CLI process (if spawned by this client) Example: // If normal

()

Source from the content-addressed store, hash-verified

545// client.ForceStop()
546// }
547func (c *Client) ForceStop() {
548 // Kill the process without waiting for startStopMux, which Start may hold.
549 // This unblocks any I/O Start is doing (connect, version check).
550 if p := c.osProcess.Swap(nil); p != nil {
551 p.Kill()
552 }
553
554 // Clear sessions immediately without trying to destroy them
555 c.sessionsMux.Lock()
556 c.sessions = make(map[string]*Session)
557 c.sessionsMux.Unlock()
558
559 c.startStopMux.Lock()
560 defer c.startStopMux.Unlock()
561
562 // Kill CLI process (only if we spawned it)
563 // This is a fallback in case the process wasn't killed above (e.g. if Start hadn't set
564 // osProcess yet), or if the process was restarted and osProcess now points to a new process.
565 if c.process != nil && !c.isExternalServer {
566 _ = c.killProcess() // Ignore errors since we're force stopping
567 }
568 c.process = nil
569
570 // Close external TCP connection if exists
571 if c.isExternalServer && c.conn != nil {
572 _ = c.conn.Close() // Ignore errors
573 c.conn = nil
574 }
575
576 // Close JSON-RPC client
577 if c.client != nil {
578 c.client.Stop()
579 c.client = nil
580 }
581
582 // Clear models cache
583 c.modelsCacheMux.Lock()
584 c.modelsCache = nil
585 c.modelsCacheMux.Unlock()
586
587 c.state = stateDisconnected
588 if !c.isExternalServer {
589 c.actualPort = 0
590 }
591
592 c.RPC = nil
593 c.internalRPC = nil
594}
595
596func (c *Client) ensureConnected(ctx context.Context) error {
597 if c.client != nil {

Calls 4

killProcessMethod · 0.95
KillMethod · 0.80
CloseMethod · 0.65
StopMethod · 0.45