Skip to content

core: sweep stale local-domain socket files on Windows (#433) - #463

Open
KonradBreitsprecherBkd wants to merge 1 commit into
mainfrom
dev_cleanup-domain-socket-files
Open

KonradBreitsprecherBkd wants to merge 1 commit into
mainfrom
dev_cleanup-domain-socket-files

Conversation

@KonradBreitsprecherBkd

Copy link
Copy Markdown
Contributor

Fixes #433.

Summary

The OS tracks whether the owner is alive. No connect probes, no grace periods, so no bind/listen race:

 MakeLocalAcceptor(path)
+  SweepStaleLocalSocketsOnce()          # DeleteFile on each *.silkit AF_UNIX socket in %TEMP%\SilKit\
+                                        # fails with ERROR_SHARING_VIOLATION while the owner lives
   bind + listen
+  LocalSocketGuard::Acquire(path)       # handle without FILE_SHARE_DELETE; released by the OS on kill
+  on failure (swept in between): rebind, max 3 attempts

 ~AsioAcceptor
+  release guard
   remove socket file
-%TEMP%\92SilKitRegi<hash>.silkit
+%TEMP%\SilKit\SilKitRegi<hash>.silkit   # dedicated dir: sockets of older versions are never swept

Linux/macOS: guard and sweep are no-ops, paths unchanged.

Also: the remove-before-bind calls and CleanupEndpoint now use the non-throwing fs::remove, which a guarded file would otherwise make throw.

Evidence

  • Before: issue repro (start + Stop-Process -Force the registry 5×) → 5 files left, forever.
    After:
    run 1..5: live registry -> 1 file(s)
    after 5 kills: 1 file(s)            # each start sweeps the previous killed one
    two live registries: 2 file(s)      # live sockets are kept
    
  • New Test_LocalSocketGuard (Windows only): guarded file can't be deleted but still accepts connections; sweep removes a stale socket and keeps live sockets, regular *.silkit files, and sockets with other extensions.
  • Windows/MSVC debug: 696 unit tests, 118 integration tests pass. Linux and MinGW are left to CI.

Merge Danger

Door: two-way

Blast Radius: small

A participant and a registry of different versions connect over TCP instead of the local-domain socket, because both sides compute the registry's socket path independently. This already happens whenever their working directories differ (e.g., the registry running as a service). Peer-to-peer connections are unaffected: those URIs are advertised.

Not included: a configurable socket directory or Linux abstract sockets. Those can be follow-ups.

🤖 Generated with Claude Code

Socket files of killed processes stayed in %TEMP% forever. Each acceptor
now holds a handle on its socket file without FILE_SHARE_DELETE, so other
processes can only delete it once the owner is gone. On startup, each
process deletes the deletable *.silkit sockets in %TEMP%\SilKit\.

Default socket files move to %TEMP%\SilKit\, so sockets of older versions
are never swept. This also drops the '92' prefix from the file names.

Use the non-throwing fs::remove overloads before bind and in
CleanupEndpoint; a guarded file would otherwise throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Konrad Breitsprecher <Konrad.Breitsprecher@vector.com>
@KonradBreitsprecherBkd KonradBreitsprecherBkd added the status: ready for review Complete and waiting for a reviewer. label Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready for review Complete and waiting for a reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug/Improvement: *.silkit local-domain socket files accumulate in the temp directory after a process is killed

1 participant