[#1880] Avoid panic when cleanup finds live node - #1936
Conversation
|
The remaining CI failures appear to be unrelated to this PR:
The regular |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1936 +/- ##
==========================================
+ Coverage 76.33% 76.40% +0.06%
==========================================
Files 457 457
Lines 46068 46068
Branches 1489 1489
==========================================
+ Hits 35165 35197 +32
+ Misses 9641 9609 -32
Partials 1262 1262
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@xiao-yang25 yes, the failures seem unrelated. There is a flaky test on Windows which we need to have a closer look at some time. I re-triggered the nightly, which suffered from the same flaky test on Windows. The cleanup mechanism is not easy to get right and @elfenpiff is the final authority to tell whether this bugfix does not violate invariants. From my point of view, it should be okay and I guess we just overlooked the different behavior on Windows. |
|
@xiao-yang25 the The Rust team is currently experimenting with a new trait resolver on the nightly Rust compiler and that might cause the issue. If it persists, we will temporarily disable the Zenoh tunnle build on the unstable builds. |
|
@elBoberido Thanks for the clarification and for re-triggering the nightly. I will leave the unrelated CI failures as they are and wait for @elfenpiff's review regarding the cleanup invariants. |
|
It seems the issue with the nighty compiler fixed itself over the weekend. We now just need to wait for @elfenpiff :) |
|
Looks like nightly just needed the weekend off 😄 I’ll wait for @elfenpiff’s verdict. |
|
I am a bit hesitant to approve the PR. The reason I introduced a It should, in theory, cleanly distinguish between in set up, alive, dead, and cleanup. Somehow, it categorized in set up falsly as dead, then the cleanup branch is triggered and the next state check identifies the node as alive. The question is now: is this some weird Windows sync issue (and Windows has a lot of weirdness inside its stack), and we need to add something to the Windows platform layer, or is it a bug in Iceoryx2 in |
|
So I studied the implementation and the windows documentation. The problem seems to be that the initialization realized via file permissions can be insufficiently synchronized in Windows. In the documentation of But we cannot use this function here, since we do not have a handle - it is a foreign process and we need to acquire the file information by path, which could lead to a misclassification in the It seems that the second call to the resource cleanup established the synchronization and therefore caused a correct I will talk tomorrow to @elBoberido after a good night's sleep, and let's see what we can come up with. If we get this wrong, and my suspicion is correct, such a fix could hide the bigger, more dangerous problem. |
|
Thanks for the detailed investigation. Your concern makes sense: my change only handles the case where the second check observes the node as alive. If the state is misclassified repeatedly, cleanup could still proceed against a live node, so the change could indeed hide the more serious underlying issue. One observation from the Windows PAL implementation: I’m happy to help test a revised approach on Windows. |
|
I ran several local experiments to distinguish delayed DACL visibility from a broader lifecycle race. ObservationsIn a controlled test where the initialization files remained unchanged for two seconds, the monitor observed I also ran an isolated cross-process DACL test with 10,000 permission transitions and 20,000 reads. After explicit synchronization, it observed no stale values, path/handle mismatches, or API errors. This does not rule out every narrow race, but I could not reproduce a simple delayed DACL update. A separate stress test repeatedly created and removed a real The current Windows This appears to be a concrete path-based TOCTOU issue combined with a swallowed permission-read error. PrototypeI prototyped the following changes:
A deterministic regression confirmed that the previous With the initial read-side fix, the original 3,000-iteration stress test completed without observing Remaining observationI then ran a stronger 5,000-iteration lifecycle test. It still observed one transient One possible explanation is a separate lifecycle race: the monitor may still hold an unlocked handle from the previous lifecycle while a new lifecycle is already starting under the same path. A later state check would then see the new lifecycle as This suggests there may be two distinct effects:
The safety invariant seems to be that cleanup must not continue from incomplete or inconsistent state information. Permission-query failures should be propagated, and a later With the candidate changes, the complete Windows The lifecycle test intentionally reuses the same path very aggressively, so it may not accurately represent the original failure. I do not want to overinterpret that result. Since this touches core process-state and cleanup logic, I think these findings require further careful discussion and validation before we draw a firm conclusion. The current tests may still miss relevant assumptions or Windows-specific behavior. |
Notes for Reviewer
During concurrent node creation on Windows, a starting node can temporarily be classified as dead. When stale-resource cleanup rechecks the node state, the monitoring layer correctly returns
MonitoringCreateCleanerError::InstanceStillAlive.This result was previously handled with
fatal_panic!, terminating the unrelated process performing the cleanup.This PR:
InstanceStillAlivetoNodeCleanupFailure::ResourcesAlreadyCleanedUp;Windows reproducer before the fix:
After the fix:
The same reproducer was also exercised on macOS/aarch64, Linux/aarch64 (Jetson Orin), and Linux/x86_64. Across 5,760 concurrent node creations, no processes were killed.
Validation
cargo fmt --all -- --checkPre-Review Checklist for the PR Author
References
Closes #1880