-
Notifications
You must be signed in to change notification settings - Fork 125
Crash fix: HTTP2Connections emit events after the pool has closed them. #481
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
Crash fix: HTTP2Connections emit events after the pool has closed them. #481
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a comment/question.
// Connections report events back to us, if they are in a shutdown that was | ||
// initiated by the state machine. For this reason this callback might be invoked |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't quite make sense to me. I think you're saying that we can still receive events after shutdown was initiated by the state machine, and when that happens http2Connections
will be nil
and we can safely ignore the event?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be worth adding a comment where http2Connections
is declared on L31 saying when we expect it to be nil
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder if http2Connections
ever needs to be nil
-- presumably we can just remove all connections from it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only reason why we made it optional was to free some memory early. I think it would make the code clearer if we make it non-optional e.g.: after we have closed a connection we set it to nil if it is empty.
Lines 543 to 545 in 12130d3
if self.http2Connections?.isEmpty == true { | |
self.http2Connections = nil | |
} |
Instead we could just check if it is empty in all places where we currently check that it is nil e.g. during shutdown and make
http2Connections
non-optional.
The same is true in the HTTP2StateMachine
for http1Connections
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnadoba will fix this in a follow up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fix the issue, thanks! New test cases look also good for HTTP2Connections
and HTTP2StateMachine
. Just one nit: maybe we should also add one test case for the HTTP1StateMachine
.
On the swift-server slack a crash was reported:
The problem here is: HTTP2Connections continue to emit events even after the pool has decided to shut them down, since the connections reference the pool as a
let delegate
. The pool must be resilient enough to ignore these events.