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

feat: add ShutdownWithContext #1383

Merged
merged 1 commit into from
Nov 20, 2022

Conversation

li-jin-gou
Copy link
Contributor

@li-jin-gou li-jin-gou commented Sep 20, 2022

pr for #1389

  • add ShutdownWithContext function to support shutdown with timeout and timeout happen after all listener already close.

select {
case <-ctx.Done():
err = ctx.Err()
break END
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering, should this then force close all connections? What does net/http do in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@li-jin-gou li-jin-gou Oct 6, 2022

Choose a reason for hiding this comment

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

I'm wondering, should this then force close all connections? What does net/http do in this case?

The use of Shutdown does not force all connections to close, but rather uses context to control the timeout after all listener have been closed.

@pjebs
Copy link
Contributor

pjebs commented Oct 6, 2022

func (s *Server) Shutdown() error { should be equivalent to s.ShutdownWithContext (context.Background())

@pjebs
Copy link
Contributor

pjebs commented Oct 6, 2022

Perhaps call the function Close instead. Remember it must try and gracefully shutdown first until context expires, then it kills all connections and shutsdown comprehensively.

ln := fasthttputil.NewInmemoryListener()
s := &Server{
Handler: func(ctx *RequestCtx) {
ctx.Success("aaa/bbb", []byte("real response"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a time.Sleep(time.Millisecond*100) here and test that ShutdownWithContext returns correctly after the timeout? The test you have now just tests the code that is similar to what TestShutdown already tests. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@li-jin-gou li-jin-gou force-pushed the feat/shutdown_ctx branch 7 times, most recently from 536e21c to 88c5c84 Compare November 17, 2022 18:59
@erikdubbelboer erikdubbelboer merged commit 4995135 into valyala:master Nov 20, 2022
@erikdubbelboer
Copy link
Collaborator

Thanks!

@pjebs
Copy link
Contributor

pjebs commented Nov 20, 2022

When will it be tagged?

@erikdubbelboer
Copy link
Collaborator

Next week I'll tag a release.

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.

3 participants