Skip to content

Conversation

@yim-lee
Copy link
Member

@yim-lee yim-lee commented Jul 19, 2022

Resolves #821

@yim-lee
Copy link
Member Author

yim-lee commented Jul 19, 2022

Hmm, test failures were all in ActorLeakingTests.
https://ci.swiftserver.group/job/swift-distributed-actors-5.7-prb/106/

[Edit]: Fixed in 7460615

@yim-lee yim-lee requested a review from ktoso July 19, 2022 22:40
}
Task {
await context.system.cluster.events.subscribe(onClusterEventRef)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
} // TODO(send): anther call site benefitting from `send`

Copy link
Member

@ktoso ktoso Jul 20, 2022

Choose a reason for hiding this comment

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

Again racy -- can't access context from other task/thread.

Maybe we should make a nonisolated func subscribe() and that should do the Task{} inside there? this is too risky;

context.subReceive(Cluster.Event.self) { event in
self.onClusterEvent(context, event: event)
}
)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't thread-safe now 😱

Cannot access context from a different task.

Oh man the lack of send hurts real bad here...

Copy link
Member

@ktoso ktoso Jul 20, 2022

Choose a reason for hiding this comment

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

let eventStream = context.system.cluster.events

let subReceive = context.subReceive(Cluster.Event.self) { event in
    self.onClusterEvent(context, event: event)
}

Task { await eventStream.subscribe(subReceive) } // TODO(send): lack of send was super problematic here, we'd have caused a race condition by accessing `context` from `Task` (!!!)

Copy link
Member Author

Choose a reason for hiding this comment

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

😱 will fix

Copy link
Member

Choose a reason for hiding this comment

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

FYI @DougGregor some "fun" examples how missing send and therefore forcing people into entering a Task{} just to call a void async function is causing all kinds of ugly code and race conditions when integrating with other code.

context.log.trace("Configured with \(self.election)")
context.system.cluster.events.subscribe(context.myself)
Task {
await context.system.cluster.events.subscribe(context.myself)
Copy link
Member

Choose a reason for hiding this comment

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

We can't touch behavior actor context from a different task ,this is racy -- needs the same fix as the other place, get the events into a let before the task

Copy link
Member

Choose a reason for hiding this comment

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

Eh sorry I merged before you had a chance to address this one @yim-lee

}
context.system.cluster.events.subscribe(onClusterEventRef)
Task {
await context.system.cluster.events.subscribe(onClusterEventRef)
Copy link
Member

Choose a reason for hiding this comment

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

Same issue; let's move to nonisolated func subscribe() { Task { so we can avoid this issue

Copy link
Member

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

LGTM, just need to fix those context accesses - preferably by a nonisolated not async func on the event stream that does the Task { for us

@ktoso
Copy link
Member

ktoso commented Jul 20, 2022

LGTM, very nice cleanup -- less and less behaviors in the codebase :)

A little bitter sweet... 😅 🥲

@ktoso ktoso merged commit cd57b91 into apple:main Jul 20, 2022
yim-lee added a commit to yim-lee/swift-distributed-actors that referenced this pull request Jul 20, 2022
yim-lee added a commit to yim-lee/swift-distributed-actors that referenced this pull request Jul 20, 2022
ktoso pushed a commit that referenced this pull request Jul 20, 2022
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.

Consider removing general purpose EventStream

2 participants