Close closes the underlying tunnel client SSH connection.
()
| 105 | |
| 106 | // Close closes the underlying tunnel client SSH connection. |
| 107 | func (c *CodespaceConnection) Close() error { |
| 108 | // Lock the mutex to prevent race conditions with the underlying SSH connection |
| 109 | c.TunnelClient.mu.Lock() |
| 110 | defer c.TunnelClient.mu.Unlock() |
| 111 | |
| 112 | // Don't close if we're not connected |
| 113 | if c.TunnelClient != nil && c.TunnelClient.connected { |
| 114 | if err := c.TunnelClient.Close(); err != nil { |
| 115 | return fmt.Errorf("failed to close tunnel client connection: %w", err) |
| 116 | } |
| 117 | |
| 118 | c.TunnelClient.connected = false |
| 119 | } |
| 120 | |
| 121 | return nil |
| 122 | } |
| 123 | |
| 124 | // getTunnelManager creates a tunnel manager for the given codespace. |
| 125 | // The tunnel manager is used to get the tunnel hosted in the codespace that we |