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: properly terminate inbound SSE connections #22

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

cwaldren-ld
Copy link
Contributor

There are various contract tests that do something like:

serveStreamingConnection()
assertSomething()

breakConnection()

serverAnotherStreamingConnection()
assertSomethingElse()

It appears that the code that was supposed to terminate inbound HTTP connections (breakConnection) was incorrect/not doing anything.

Reading the docs for http.Request:

// Context returns the request's context. To change the context, use
// WithContext.
//
// The returned context is always non-nil; it defaults to the
// background context.
//
// For outgoing client requests, the context controls cancellation.
//
// For incoming server requests, the context is canceled when the
// client's connection closes, the request is canceled (with HTTP/2),
// or when the ServeHTTP method returns.

Note the emphasis. For incoming server requests, the context is canceled by the server, not by calling the context.Cancel function. Therefore, all the machinery related to storing context cancellation functions, invoking them, etc. is not going to work - we should let the handlers return, and the server do its job.

I've also added a new contract test to be sure that clients which don't support restart capability still have their re-connection code exercised.

Copy link
Member

@keelerm84 keelerm84 left a comment

Choose a reason for hiding this comment

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

No one has been added as a reviewer, but the changes seem sane based on what you say.

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