Fix Client#end causing issues with daemon
MODIFY
packages/@romejs/core/client/Client.ts
packages/@romejs/core/client/Client.ts
@@ -67,6 +67,7 @@ type BridgeStatus = BridgeStatusDedicated | BridgeStatusLocal;
type BridgeStatusDedicated = {
bridge: ServerBridge;
dedicated: true;
+ socket: net.Socket;
};
type BridgeStatusLocal = {
@@ -443,12 +444,9 @@ export default class Client {
return this.bridgeStatus;
}
- async end() {
- await this.endEvent.callOptional();
-
+ async shutdownServer() {
const status = this.bridgeStatus;
- if (status !== undefined) {
- if (status.bridge.alive) {
+ if (status !== undefined && status.bridge.alive) {
try {
await status.bridge.endServer.call();
} catch (err) {
@@ -459,10 +457,25 @@ export default class Client {
}
}
}
- this.bridgeStatus = undefined;
+
+ await this.end();
+ }
+
+ async end() {
+ await this.endEvent.callOptional();
+ const status = this.bridgeStatus;
+
+ if (status !== undefined && status.bridge.alive) {
+ if (status.dedicated) {
+ status.socket.end();
+ } else {
+ await this.shutdownServer();
}
}
+ this.bridgeStatus = undefined;
+ }
+
async attachBridge(status: BridgeStatus) {
const {stdout, stderr, columnsUpdated} = this.derivedReporterStreams;
const {reporterOverrides = {}} = this.options;
@@ -657,6 +670,10 @@ export default class Client {
}
async tryConnectToExistingDaemon(): Promise<undefined | ServerBridge> {
+ if (this.bridgeStatus !== undefined) {
+ return this.bridgeStatus.bridge;
+ }
+
const promise: Promise<undefined | net.Socket> = new Promise((
resolve,
reject,
@@ -698,7 +715,7 @@ export default class Client {
type: "server",
},
);
- await this.attachBridge({bridge, dedicated: true});
+ await this.attachBridge({socket, bridge, dedicated: true});
this.reporter.success("Connected to daemon");
return bridge;
}

MODIFY
packages/@romejs/core/server/Server.ts
packages/@romejs/core/server/Server.ts
@@ -481,6 +481,10 @@ export default class Server {
// We should remove everything that has an external dependency like a socket or process
await this.endEvent.callOptional();
this.workerManager.end();
+
+ if (this.options.dedicated) {
+ process.exit();
+ }
}
async attachToBridge(bridge: ServerBridge): Promise<ServerClient> {

Fix Client#end causing issues with daemon (#684)