Skip to content

Conversation

dcantah
Copy link
Member

@dcantah dcantah commented Oct 9, 2025

This change moves LinuxContainer to use the new AsyncMutex type. This allows us to keep
using our old state machine model, but lock around the entirety of operations. This also
allows us to axe quite a few states that were intermediary states only there to protect against
multiple threads calling (even if it was unlikely..) the same method at the same time (.creating,
.starting, .stopping etc.).

The rationale is: Mutex is somewhat tricky to use as you can't (for good reason) do any async
work inside the closure. This makes some of our work difficult as every single interaction
with the guest is via an rpc, which is all async. There really isn't a worry about contention,
because most container methods will only ever be invoked once (create, start, stop) so a big heavy
lock isn't much of a deterrent.

This change moves LinuxContainer to use the new AsyncMutex type. This allows us to keep
using our old state machine model, but lock around the entirety of operations. This also
allows us to axe quite a few states that were intermediary states only there to protect against
multiple threads calling (even if it was unlikely..) the same method at the same time (.creating,
.starting, .stopping etc.).

The rationale is: Mutex is somewhat tricky to use as you can't (for good reason) do any async
work inside the closure. This makes some of our work difficult as every single interaction
with the guest is via an rpc, which is all async. There really isn't a worry about contention,
because most container methods will only ever be invoked once (create, start, stop) so a big heavy
lock isn't much of a deterrent.
@dcantah dcantah force-pushed the linuxcontainer-async-lockify branch from 390629c to 9ae4b51 Compare October 9, 2025 21:03
Copy link
Contributor

@katiewasnothere katiewasnothere left a comment

Choose a reason for hiding this comment

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

lgtm

@dcantah dcantah merged commit d0383eb into apple:main Oct 9, 2025
2 checks passed
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.

2 participants