Fix bug where channel could outlive event loop #536
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
Crashes in aws-crt-python if a WebSocket outlived an EventLoopGroup.
Investigation:
aws_channel
is refcounted. It uses anaws_event_loop
, but event loops do not currently support refcounting.The
aws_event_loop_group
is refcounted, butaws_channel
only currently knows about an individual loop.So it's possible for the refcount on aws_event_loop_group to go to 0, and all the loops are destroyed, before the channel's refcount goes to zero, and it tries to schedule a task on the loop, and everything explodes because the loop was already cleaned up
Description of changes:
Add new function
aws_event_loop_group_acquire_hold_on_group(struct aws_event_loop *);
so that channel can refcount the group, even though it only has access to the individual loopI considered adding a proper refcount to individual the aws_event_loop, but there's a good bit of code that assumes the lifetime of the loops is tied to the lifetime of the group, so I didn't want to break that assumption.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.