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: alive connections counter for graceful shutdown #526

Merged
merged 2 commits into from
Mar 10, 2023

Conversation

DDtKey
Copy link
Contributor

@DDtKey DDtKey commented Mar 7, 2023

It's currently looks a bit fragile:
It's possible to spawn new future, but parallel task will finish before spawned task is polled.
So this check will notify waiter & stop server:

if alive_connections.fetch_sub(1, Ordering::SeqCst) == 1 {
    notify.notify_one();
}

It's hard to test, however sometimes we're encountering connection reset errors on client end, while server side almost immediately logged correct graceful shutdown & server stopped (we use large enough timeout, so it's not the case)

I believe it's more reliable & safe to increase counter before spawning the task of serving.

@@ -135,9 +135,8 @@ where
let notify = notify.clone();
let timeout_notify = timeout_notify.clone();

alive_connections.fetch_add(1, Ordering::SeqCst);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Btw, I see SeqCst is used here and it's strict.
Probably it should be refactored to Acquire/Release 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you help me with this? 🙂

Copy link
Contributor Author

@DDtKey DDtKey Mar 10, 2023

Choose a reason for hiding this comment

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

Sure!

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks 🙂

@DDtKey DDtKey force-pushed the fix-connection-counting branch from 64ff07c to c58770b Compare March 10, 2023 09:06
@DDtKey DDtKey force-pushed the fix-connection-counting branch from 1e43bc3 to 7abaa10 Compare March 10, 2023 09:46
@sunli829 sunli829 merged commit 813a2a8 into poem-web:master Mar 10, 2023
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.

2 participants