Skip to content

Commit

Permalink
feat(cli): wait for client on create/unlock
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sangaman committed Sep 25, 2019
1 parent f32fe6d commit a6b1d97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/cli/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export const handler = (argv: Arguments) => {
if (password1 === password2) {
const request = new CreateNodeRequest();
request.setPassword(password1);
loadXudInitClient(argv).createNode(request, callback(argv, formatOutput));
const client = loadXudInitClient(argv);
// wait up to 3 seconds for rpc server to listen before call in case xud was just started
client.waitForReady(Date.now() + 3000, () => {
client.createNode(request, callback(argv, formatOutput));
});
} else {
console.log('Passwords do not match, please try again.');
}
Expand Down
6 changes: 5 additions & 1 deletion lib/cli/commands/unlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export const handler = (argv: Arguments) => {
rl.close();
const request = new UnlockNodeRequest();
request.setPassword(password);
loadXudInitClient(argv).unlockNode(request, callback(argv));
const client = loadXudInitClient(argv);
// wait up to 3 seconds for rpc server to listen before call in case xud was just started
client.waitForReady(Date.now() + 3000, () => {
client.unlockNode(request, callback(argv));
});
});
};

0 comments on commit a6b1d97

Please sign in to comment.