Repository navigation
Per-process sandboxer socket path - #23720
Conversation
|
LLM disclosure: Claude made the change under my guidance. |
|
I tested this out to see if it fixes #23716 and it gets us most of the way there. Seems like we need to also set max_readers to a higher value (like 2048) to fully resolve the issue. I asked Claude to re-enable the sandboxer in our repo and then come up with a scenario that reproduces the issue we saw that's documented in the issue. This used Pants 2.32.0. For fun, I asked it to run that same scenario both against Pants Full response courtesy of Opus 5.5:
|
3d01407 to
4d122ec
Compare
|
Thanks @hopper-signifyd - I've applied that patch to increase the reader slots (and slightly modified it). |
|
I'll take that patch for the "Optional hardening" if you have it |
I think it was one of these. Let me re-run my tests against the current state of the branch and get back to you |
|
Okay, I had Claude re-evaluate things. Looks like this branch in its current state solves the issues I'd originally reported. Ignore the patches I uploaded yesterday. This one is the new one Claude is suggesting: Full result output from Claude:
|
|
Thanks. I already took my own stab at the "hardening", only part of it though, since the connection draining is a lot of new code and doesn't seem that necessary. |
4d122ec to
cfd730a
Compare
| /// The pid of the spawning process. The sandboxer exits if this process exits. | ||
| /// If unspecified, the sandboxer's parent process at startup is used. | ||
| #[arg(long)] | ||
| parent_pid: Option<u32>, |
There was a problem hiding this comment.
Previously we assumed that the pid we capture when we first start up is the parent pid, but we might get reparented even before that happens, so we now receive it on startup from the parent.
|
cc reviewers, thanks! |
A pants process that opened the local store more than once and dropped one copy lost its LMDB locks while the other copy kept writing. So another process could write the same shard at the same time and corrupt it on disk. `--no-pantsd` with a bootstrap scheduler and test processes with one `RuleRunner` per test both did this. [LMDB says to not open the store more than once in the same process for this reason](https://github.com/mozilla/lmdb/blob/b7df2cac50fb41e8bd16aab4cc5fd167be9e032a/libraries/liblmdb/lmdb.h#L101-L104) With this PR: - Stores in one process now share each shard's LMDB environment through a registry keyed by the lock file's device and inode. An environment is closed once no store holds it. - A process forked from the one that owns the registry cannot open a store. Nothing does this today. - A shared environment keeps its map size, so opening the store at a larger size in the same process is an error, and `local_store_shard_count` and the `local_store_*_max_size_bytes` options now restart pantsd. This is needed because the new scheduler is built before the old is released, and currently the old scheduler is also leaked anyways. So it's a larger change to first close it to open it with a new shard count or similar. Tests added to cover the new path, and one of the tests fail on main by dropping one of the stores leaving the other without locks. Also tested end-to-end on MacOS with a debug-engine where a process that dropped a second store, writing beside a process with one `RuleRunner` per test, damaged a shard within seconds on main and ran 60 s without damage with this change. Since #23720, each process that opens the store runs `mdb_reader_check`, which frees the reader slots of any process that holds no liveness lock, so a process that lost its locks also loses the protection of its open read transactions. This change removes the lock loss. Disclosure: Implemented and verified with Claude with human direction
Concurrent Pants processes in the same buildroot would step on each
others' sandboxers because they all attempted to use the same socket path.
This ensures that each process has its own sandboxer socket path and therefore
its own dedicated sandboxer.
Also fixes a couple of flaky tests.
Fixes #23716