Repository navigation
fix(windows): join the async reader before releasing the adapter - #6
Merged
Merged
Conversation
Dropping AsyncDevice used to detach the blocking reader thread. Its session reference could keep the old adapter alive after drop returned, so immediately reopening the same name raced session teardown. Close the packet receiver, signal shutdown and join the reader before releasing the remaining session reference. Closing the receiver also stops a reader that is continuously receiving packets. Treat its closed channel as normal shutdown. Add an opt-in Windows regression test that recreates a fixed-name, fixed-GUID adapter 100 times while another adapter remains active and checks that each dropped device releases every session reference. Validation: the regression test passes on Windows 11 with Wintun 0.14.1; cargo fmt --all -- --check passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Dropping a Windows
AsyncDevicecould return while its blocking reader still owned the Wintun session and adapter. An immediate same-name restart could then reopen that adapter before teardown finished, producingERROR_ALREADY_INITIALIZEDor racing adapter removal.Close the packet receiver, signal session shutdown, and join the reader before releasing the final session reference. Closing the channel also lets the worker exit when the receive ring stays busy. A closed channel during teardown is no longer logged as an error.
Validation on Windows 11 build 22621 with Wintun 0.14.1:
cargo fmt --all -- --checkpassed.io_other_error,needless_lifetimes, anduseless_conversionlints allowed. Unfiltered-D warningsis blocked by pre-existing findings inerror.rs,address.rs, and Windows platform code; this patch does not change those files.EasyTier/EasyTier#2694 pins this commit and removes the random adapter-name workaround. Related: EasyTier/EasyTier#110 and EasyTier/EasyTier#2682.
Close-latency measurements on the same Windows 11 VM (release build, x86_64-pc-windows-gnu, 4 MiB rings, 30 samples per version/scenario):
The timer encloses only
drop(AsyncDevice), excluding adapter creation, address configuration, and workload setup. The traffic case consumed roughly 66k packets/s; the backlog case left 16.8k–22.3k packets queued in the fixed build. The sender continued running during drop. Old drop can return while its detached worker is still performing teardown, which explains its lower return latency.An additional diagnostic experiment kept one session reference until after device drop, separating worker/queue cleanup from final session/adapter release (10 samples per scenario). Median worker/queue cleanup was 0.095 ms idle, 0.213 ms under continuous traffic, and 3.143 ms with backlog. Final session/adapter release medians were 67.748, 29.861, and 30.724 ms respectively. This identifies final resource release as the main observed cost. The sender was stopped before the separately timed final release.
All 180 full-drop samples and 30 split samples passed. No measured close reached one second. These finite measurements on one VM do not establish a hard upper bound: the synchronous thread join still has no timeout. Benchmark instrumentation was confined to test-only source copies; this PR implementation was unchanged.