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 race condition in cycle detector block sent handling #3666

Merged
merged 1 commit into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .release-notes/cd-double-free.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Fix race condition that can result in a segfault

We recently introduced some improvements to the handling of garbage collection for short-lived actors when the cycle detector is running. In the process, we introduced a race condition in the runtime that could result in an actor being garbage collected twice which if it were to occur, would result in a crashing program.
11 changes: 9 additions & 2 deletions src/libponyrt/actor/actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,16 @@ static bool handle_message(pony_ctx_t* ctx, pony_actor_t* actor,
#endif

pony_assert(!ponyint_is_cycle(actor));
if(has_flag(actor, FLAG_BLOCKED) && !has_flag(actor, FLAG_BLOCKED_SENT))
if(has_flag(actor, FLAG_BLOCKED)
&& !has_flag(actor, FLAG_BLOCKED_SENT)
&& (actor->gc.rc > 0))
{
// We're blocked, send block message.
// We're blocked, send block message if:
// - the actor hasn't already sent one
// - the actor aren't a zombie aka rc == 0
//
// Sending multiple "i'm blocked" messages to the cycle detector
// will result in actor potentially being freed more than once.
set_flag(actor, FLAG_BLOCKED_SENT);
pony_assert(ctx->current == actor);
ponyint_cycle_block(actor, &actor->gc);
Expand Down