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

Atomic-less approach to fixing the double release race condition #102

Closed
wants to merge 1 commit into from

Conversation

bretambrose
Copy link
Contributor

@bretambrose bretambrose commented Jul 3, 2023

Ensure that the continuation completion callbacks and its table-remove/decref only get performed once no matter what the situation.

Greengrass has a high-level repro and the logs show the completion callback and the decref inside occuring twice for the same continuation, once due to terminate stream flags on the outbound client socket write callback and once due to terminate stream flags received in the meantime from the server's response.

I was not able to come up with a test with the existing framework that triggered this condition.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

aws_mutex_unlock(&connection->stream_lock);

/* Note that we do not invoke callback while holding lock */
s_complete_continuation(continuation);
if (was_present) {
s_complete_continuation(continuation);
Copy link
Contributor

Choose a reason for hiding this comment

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

This improves things, but I'm still worried about s_clear_continuation_table() (which is called from aws_event_stream_rpc_client_connection_close() and s_on_channel_shutdown_fn())

It seems to mark ALL continuations closed, and fire their callbacks, but does NOT remove them from the hashtable. I'm haven't dug through every possible execution path, but this seems fragile, like we could do the callback/release but leave them in the table, then callback/release again from one of these places you just fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree

@bretambrose bretambrose closed this Jul 3, 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.

3 participants