Shutdown waits for all exiting in-flight requests to complete, or the context to expire, whichever comes first.
(ctx context.Context)
| 166 | |
| 167 | // Shutdown waits for all exiting in-flight requests to complete, or the context to expire, whichever comes first. |
| 168 | func (s *Server) Shutdown(ctx context.Context) error { |
| 169 | var err error |
| 170 | s.shutdownOnce.Do(func() { |
| 171 | s.cancelFn() |
| 172 | |
| 173 | // Wait for any outstanding connections to terminate. |
| 174 | s.wg.Wait() |
| 175 | |
| 176 | select { |
| 177 | case <-ctx.Done(): |
| 178 | s.logger.Warn(ctx, "graceful shutdown failed", slog.Error(ctx.Err())) |
| 179 | err = ctx.Err() |
| 180 | return |
| 181 | default: |
| 182 | } |
| 183 | |
| 184 | s.logger.Info(ctx, "shutting down request pool") |
| 185 | if err = s.requestBridgePool.Shutdown(ctx); err != nil { |
| 186 | s.logger.Error(ctx, "request pool shutdown failed with error", slog.Error(err)) |
| 187 | } |
| 188 | |
| 189 | s.logger.Info(ctx, "gracefully shutdown") |
| 190 | }) |
| 191 | return err |
| 192 | } |
| 193 | |
| 194 | // Close shuts down the server with a timeout of 5s. |
| 195 | func (s *Server) Close() error { |