Skip to content

Commit a6b1d97

Browse files
committed
feat(cli): wait for client on create/unlock
This adds logic to wait for the xud client to be ready before attempting the `CreateNode` or `UnlockNode` calls. These calls may be made shortly after starting xud - for example as part of a bash script - and this wait of up to 3 seconds may prevent transient failures or race conditions.
1 parent f32fe6d commit a6b1d97

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/cli/commands/create.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ export const handler = (argv: Arguments) => {
5555
if (password1 === password2) {
5656
const request = new CreateNodeRequest();
5757
request.setPassword(password1);
58-
loadXudInitClient(argv).createNode(request, callback(argv, formatOutput));
58+
const client = loadXudInitClient(argv);
59+
// wait up to 3 seconds for rpc server to listen before call in case xud was just started
60+
client.waitForReady(Date.now() + 3000, () => {
61+
client.createNode(request, callback(argv, formatOutput));
62+
});
5963
} else {
6064
console.log('Passwords do not match, please try again.');
6165
}

lib/cli/commands/unlock.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const handler = (argv: Arguments) => {
2121
rl.close();
2222
const request = new UnlockNodeRequest();
2323
request.setPassword(password);
24-
loadXudInitClient(argv).unlockNode(request, callback(argv));
24+
const client = loadXudInitClient(argv);
25+
// wait up to 3 seconds for rpc server to listen before call in case xud was just started
26+
client.waitForReady(Date.now() + 3000, () => {
27+
client.unlockNode(request, callback(argv));
28+
});
2529
});
2630
};

0 commit comments

Comments
 (0)