Experiment: Wrap all capnp code in a context-manager to avoid segfaults #317
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.
This is me trying some things out. I'm aware that @haata hasn't signed off on #316 yet.
The main goal of this PR is to program defenses into Pycapnp such that a segfault can never be triggered from Python code. To achieve this, I've used the following strategy:
async with capnp.kj_loop():
.AsyncIoStream
's, (2) openTwoPartyServer
's andTwoPartyClient
's and (3) ongoing capability method calls.RpcSystem
andVatNetwork
associated with any servers and clients (without actually killing the python-level server and client objects, but they do become unusable). This is because when you destroy these C++ objects, they schedule a task in the KJ loop. So we have to destroy these objects before destroying the loop.CapabilityClient
objects around that are backed by a closedTwoPartyClient
. We need to guard any method call on those to ensure we don't segfault.I've added a bunch of tests that used to segfault. Most likely there are more, but my theory is that with the current approach, we can solve all of those.
Feedback from @haata and @kentonv is appreciated on the validity of this approach.
Fixes #316