Shutdown stops accepting new connections. The current implementation calls Close() for simplicity instead of waiting for existing connections to close. If the context times out, Shutdown will return but Close() may not have completed.
(ctx context.Context)
| 1252 | // connections to close. If the context times out, Shutdown will return |
| 1253 | // but Close() may not have completed. |
| 1254 | func (s *Server) Shutdown(ctx context.Context) error { |
| 1255 | ch := make(chan error, 1) |
| 1256 | go func() { |
| 1257 | // TODO(mafredri): Implement shutdown, SIGHUP running commands, etc. |
| 1258 | // For now we just close the server. |
| 1259 | ch <- s.Close() |
| 1260 | }() |
| 1261 | var err error |
| 1262 | select { |
| 1263 | case <-ctx.Done(): |
| 1264 | err = ctx.Err() |
| 1265 | case err = <-ch: |
| 1266 | } |
| 1267 | // Re-check for context cancellation precedence. |
| 1268 | if ctx.Err() != nil { |
| 1269 | err = ctx.Err() |
| 1270 | } |
| 1271 | if err != nil { |
| 1272 | return xerrors.Errorf("close server: %w", err) |
| 1273 | } |
| 1274 | return nil |
| 1275 | } |
| 1276 | |
| 1277 | func isLoginShell(rawCommand string) bool { |
| 1278 | return len(rawCommand) == 0 |