fix: close daemon socket after programmatic load() to prevent process hang#717
Draft
Copilot wants to merge 2 commits into
Draft
fix: close daemon socket after programmatic load() to prevent process hang#717Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
- Add socket.unref() in DaemonClient.connectToSocket so the idle socket does not keep the event loop alive after all messages have resolved. - Add cleanupDaemonClient() helper in local-encrypt/index.ts. - Call cleanupDaemonClient() at the end of the programmatic load() function so the daemon socket is explicitly closed after env resolution completes. - Export a public cleanup() function from varlock/src/index.ts for programmatic users who want explicit lifecycle control.
Copilot
AI
changed the title
[WIP] Fix daemon socket remaining open after keychain resolution
fix: close daemon socket after programmatic load() to prevent process hang
May 25, 2026
Member
|
@theoephraim might be unnecessary (see linked issue) feel free to close |
Member
|
seems reasonable, but currently we dont even talk about using load() anywhere, or provide any other guidance. Im wondering if we should get rid of it, or at least mark it as internal or something 🤷 |
Member
yeah I'll defer to you there. I think we can close |
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.
After
await load()resolveskeychain(...)values, the process hangs because the daemon client's Unix socket (~/.varlock/local-encrypt/daemon.sock) remains open and ref'd, keeping the event loop alive indefinitely.Changes
daemon-client.ts— Callsocket.unref()on connect. The idle socket no longer holds the event loop open. In-flightsendMessagecalls are unaffected: theirsetTimeouttimers keep the event loop alive while waiting for responses (including biometric/interactive ops with their 5-min timeout).local-encrypt/index.ts— AddcleanupDaemonClient()helper that callscleanup()on the singleton if one was created. Belt-and-suspenders for runtimes whereunref()alone may not suffice.index.ts— CallcleanupDaemonClient()at the end ofload(), and export a publiccleanup()for users who need explicit lifecycle control: