Stop gracefully stops the OAuth callback server. It performs a graceful shutdown of the HTTP server with a timeout. Parameters: - ctx: The context for controlling the shutdown process Returns: - error: An error if the server fails to stop gracefully
(ctx context.Context)
| 114 | // Returns: |
| 115 | // - error: An error if the server fails to stop gracefully |
| 116 | func (s *OAuthServer) Stop(ctx context.Context) error { |
| 117 | s.mu.Lock() |
| 118 | defer s.mu.Unlock() |
| 119 | |
| 120 | if !s.running || s.server == nil { |
| 121 | return nil |
| 122 | } |
| 123 | |
| 124 | log.Debug("Stopping OAuth callback server") |
| 125 | |
| 126 | // Create a context with timeout for shutdown |
| 127 | shutdownCtx, cancel := context.WithTimeout(ctx, 5*time.Second) |
| 128 | defer cancel() |
| 129 | |
| 130 | err := s.server.Shutdown(shutdownCtx) |
| 131 | s.running = false |
| 132 | s.server = nil |
| 133 | |
| 134 | return err |
| 135 | } |
| 136 | |
| 137 | // WaitForCallback waits for the OAuth callback with a timeout. |
| 138 | // It blocks until either an OAuth result is received, an error occurs, |