fix: add 3s timeout to keychain init to prevent hang on Linux SSH sessions#16
Open
Slach wants to merge 2 commits intoportel-dev:mainfrom
Open
fix: add 3s timeout to keychain init to prevent hang on Linux SSH sessions#16Slach wants to merge 2 commits intoportel-dev:mainfrom
Slach wants to merge 2 commits intoportel-dev:mainfrom
Conversation
… display On Linux in SSH sessions without DISPLAY/WAYLAND_DISPLAY, the gnome-keyring-daemon may be running but locked. libsecret's D-Bus calls then wait indefinitely for a GUI unlock dialog that never appears, causing `ncp list` and all other commands to hang forever with no output. Add a 3-second Promise.race timeout around the keychain test. On timeout the code falls back to the existing encrypted-file credential storage, so all NCP functionality continues to work correctly in headless/SSH environments. Fixes: ncp list hanging in SSH sessions on Linux even with gnome-keyring running. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
As a workaround, I used |
@napi-rs/keyring uses native N-API which runs synchronously on the Node.js main thread. On Linux without DISPLAY/WAYLAND_DISPLAY (SSH/headless), the gnome-keyring-daemon is running but locked — libsecret's D-Bus call blocks the entire event loop waiting for a GUI unlock dialog that never appears. Promise.race with setTimeout cannot help here because the native call holds the event loop and setTimeout never fires. Fix: check for Linux + no display before importing @napi-rs/keyring at all, and fall back immediately to encrypted file storage. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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.
Problem
On Linux in SSH sessions without
DISPLAYorWAYLAND_DISPLAY,ncp listand all other NCP commands hang forever with no output and no log entries — even with--debug.Root cause:
SecureCredentialStore.initializeKeychain()callstestEntry.setPassword('test')via@napi-rs/keyring(libsecret). Whengnome-keyring-daemonis running but the vault is locked, libsecret issues a D-Bus call and waits indefinitely for a GUI unlock dialog that never appears in a headless environment. There is no timeout on this operation.Reproduction:
Confirmed with:
Fix
Wrap the keychain test (
setPassword/getPassword/deletePassword) in aPromise.racewith a 3-second timeout. On timeout, the error is caught and the code falls back to the existing encrypted-file credential storage (~/.ncp/tokens/). All NCP functionality continues to work correctly in headless/SSH environments.Test plan
ncp listin SSH session without DISPLAY no longer hangs (exits in <4s)ncp listin a normal desktop session still uses OS keychain as beforeOS keychain unavailable, using encrypted file storage: Keychain test timed out after 3000ms🤖 Generated with Claude Code