Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext/http): create a graceful shutdown API #20387

Merged
merged 8 commits into from Sep 12, 2023

Conversation

mmastrac
Copy link
Member

@mmastrac mmastrac commented Sep 5, 2023

This PR implements a graceful shutdown API for Deno.serve, allowing all current connections to drain from the server before shutting down, while preventing new connections from being started or new transactions on existing connections from being created.

We split the cancellation handle into two parts: a listener handle, and a connection handle. A graceful shutdown cancels the listener only, while allowing the connections to drain. The connection handle aborts all futures. If the listener handle is cancelled, we put the connections into graceful shutdown mode, which disables keep-alive on http/1.1 and uses http/2 mechanisms for http/2 connections.

In addition, we now guarantee that all connections are complete or cancelled, and all resources are cleaned up when the server finished promise resolves -- we use a Rust-side server refcount for this.

Performance impact: does not appear to affect basic serving performance by more than 1% (~126k -> ~125k)

@mmastrac mmastrac changed the title [WIP] fix(ext/http): create a graceful shutdown API fix(ext/http): create a graceful shutdown API Sep 6, 2023
@mmastrac mmastrac force-pushed the http_shutdown branch 2 times, most recently from 6eb1645 to 58a4c26 Compare September 8, 2023 20:30
cli/tests/unit/serve_test.ts Show resolved Hide resolved
ext/http/slab.rs Show resolved Hide resolved
ext/http/00_serve.js Outdated Show resolved Hide resolved
ext/http/00_serve.js Show resolved Hide resolved
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mmastrac mmastrac enabled auto-merge (squash) September 12, 2023 00:02
@mmastrac mmastrac merged commit 950e0e9 into denoland:main Sep 12, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants