Skip to content

Commit 9822d77

Browse files
committed
feat: shutdown xud on error during init
This commit shuts down `xud` when there is an unexpected error during initialization. Allowing it to continue could result in an unexpected or undesirable state without the user being aware. Shutting down prompts the user to investigate and correct the error before restarting.
1 parent b9fd676 commit 9822d77

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

lib/Xud.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,19 @@ class Xud extends EventEmitter {
161161

162162
if (!this.config.webproxy.disable) {
163163
this.grpcAPIProxy = new GrpcWebProxyServer(loggers.rpc);
164-
try {
165-
await this.grpcAPIProxy.listen(
166-
this.config.webproxy.port,
167-
this.config.rpc.port,
168-
this.config.rpc.host,
169-
path.join(this.config.xudir, 'tls.cert'),
170-
);
171-
} catch (err) {
172-
this.logger.error('Could not start gRPC web proxy server', err);
173-
}
164+
await this.grpcAPIProxy.listen(
165+
this.config.webproxy.port,
166+
this.config.rpc.port,
167+
this.config.rpc.host,
168+
path.join(this.config.xudir, 'tls.cert'),
169+
);
174170
}
175171
} else {
176-
this.logger.warn('RPC server is disabled.');
172+
this.logger.info('RPC server is disabled.');
177173
}
178174
} catch (err) {
179-
this.logger.error('Unexpected error during initialization', err);
175+
this.logger.error('Unexpected error during initialization, shutting down...', err);
176+
await this.shutdown();
180177
}
181178
}
182179

lib/grpc/webproxy/GrpcWebProxyServer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class GrpcWebProxyServer {
3838
return new Promise<void>((resolve, reject) => {
3939
/** A handler to handle an error while trying to begin listening. */
4040
const listenErrHandler = (err: Error) => {
41+
this.logger.error('Error on web proxy beginning to listen', err);
4142
reject(err);
4243
};
4344

0 commit comments

Comments
 (0)