Handle disconnects (#363)
* Make proxies decide how to handle disconnects * Connect to a new terminal instance on disconnect * Use our retry for the watcher * Specify method when proxy doesn't exist * Don't error when closing/killing disconnected proxy * Specify proxy ID when a method doesn't exist * Use our retry for the searcher Also dispose some things for the watcher because it doesn't seem that was done properly. The searcher also now starts immediately so there won't be lag when you perform your first search. * Use our retry for the extension host * Emit error in parent proxy class Reduces duplicate code. Not all items are "supposed" to have an error event according to the original implementation we are filling, but there is no reason why we can't emit our own events (and are already doing so for the "disconnected" event anyway). * Reconnect spdlog * Add error message when shared process disconnects * Pass method resolve to parse * Don't pass method to getProxy It doesn't tell you anything that trace logging wouldn't and has no relation to what the function actually does. * Fix infinite recursion when disposing protocol client in tests
This commit is contained in:
@ -87,6 +87,11 @@ export class ChildProcess extends ClientProxy<ChildProcessProxy> implements cp.C
|
||||
|
||||
return true; // Always true since we can't get this synchronously.
|
||||
}
|
||||
|
||||
protected handleDisconnect(): void {
|
||||
this.emit("exit", 1);
|
||||
this.emit("close");
|
||||
}
|
||||
}
|
||||
|
||||
export class ChildProcessModule {
|
||||
|
@ -41,6 +41,10 @@ class Watcher extends ClientProxy<WatcherProxy> implements fs.FSWatcher {
|
||||
public close(): void {
|
||||
this.proxy.close();
|
||||
}
|
||||
|
||||
protected handleDisconnect(): void {
|
||||
this.emit("close");
|
||||
}
|
||||
}
|
||||
|
||||
class WriteStream extends Writable<WriteStreamProxy> implements fs.WriteStream {
|
||||
|
@ -126,6 +126,7 @@ export class Socket extends Duplex<NetSocketProxy> implements net.Socket {
|
||||
}
|
||||
|
||||
export class Server extends ClientProxy<NetServerProxy> implements net.Server {
|
||||
private socketId = 0;
|
||||
private readonly sockets = new Map<number, net.Socket>();
|
||||
private _listening: boolean = false;
|
||||
|
||||
@ -133,7 +134,12 @@ export class Server extends ClientProxy<NetServerProxy> implements net.Server {
|
||||
super(proxyPromise);
|
||||
|
||||
this.proxy.onConnection((socketProxy) => {
|
||||
this.emit("connection", new Socket(socketProxy));
|
||||
const socket = new Socket(socketProxy);
|
||||
const socketId = this.socketId++;
|
||||
this.sockets.set(socketId, socket);
|
||||
socket.on("error", () => this.sockets.delete(socketId))
|
||||
socket.on("close", () => this.sockets.delete(socketId))
|
||||
this.emit("connection", socket);
|
||||
});
|
||||
|
||||
this.on("listening", () => this._listening = true);
|
||||
@ -200,6 +206,10 @@ export class Server extends ClientProxy<NetServerProxy> implements net.Server {
|
||||
public getConnections(cb: (error: Error | null, count: number) => void): void {
|
||||
cb(null, this.sockets.size);
|
||||
}
|
||||
|
||||
protected handleDisconnect(): void {
|
||||
this.emit("close");
|
||||
}
|
||||
}
|
||||
|
||||
type NodeNet = typeof net;
|
||||
|
@ -6,11 +6,20 @@ export class NodePtyProcess extends ClientProxy<NodePtyProcessProxy> implements
|
||||
private _pid = -1;
|
||||
private _process = "";
|
||||
|
||||
public constructor(proxyPromise: Promise<NodePtyProcessProxy>) {
|
||||
super(proxyPromise);
|
||||
public constructor(
|
||||
private readonly moduleProxy: NodePtyModuleProxy,
|
||||
private readonly file: string,
|
||||
private readonly args: string[] | string,
|
||||
private readonly options: pty.IPtyForkOptions,
|
||||
) {
|
||||
super(moduleProxy.spawn(file, args, options));
|
||||
this.on("process", (process) => this._process = process);
|
||||
}
|
||||
|
||||
protected initialize(proxyPromise: Promise<NodePtyProcessProxy>) {
|
||||
super.initialize(proxyPromise);
|
||||
this.proxy.getPid().then((pid) => this._pid = pid);
|
||||
this.proxy.getProcess().then((process) => this._process = process);
|
||||
this.on("process", (process) => this._process = process);
|
||||
}
|
||||
|
||||
public get pid(): number {
|
||||
@ -32,6 +41,12 @@ export class NodePtyProcess extends ClientProxy<NodePtyProcessProxy> implements
|
||||
public kill(signal?: string): void {
|
||||
this.proxy.kill(signal);
|
||||
}
|
||||
|
||||
protected handleDisconnect(): void {
|
||||
this._process += " (disconnected)";
|
||||
this.emit("data", "\r\n\nLost connection...\r\n\n");
|
||||
this.initialize(this.moduleProxy.spawn(this.file, this.args, this.options));
|
||||
}
|
||||
}
|
||||
|
||||
type NodePty = typeof pty;
|
||||
@ -40,6 +55,6 @@ export class NodePtyModule implements NodePty {
|
||||
public constructor(private readonly proxy: NodePtyModuleProxy) {}
|
||||
|
||||
public spawn = (file: string, args: string[] | string, options: pty.IPtyForkOptions): pty.IPty => {
|
||||
return new NodePtyProcess(this.proxy.spawn(file, args, options));
|
||||
return new NodePtyProcess(this.proxy, file, args, options);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,16 @@ import { ClientProxy } from "../../common/proxy";
|
||||
import { RotatingLoggerProxy, SpdlogModuleProxy } from "../../node/modules/spdlog";
|
||||
|
||||
class RotatingLogger extends ClientProxy<RotatingLoggerProxy> implements spdlog.RotatingLogger {
|
||||
public constructor(
|
||||
private readonly moduleProxy: SpdlogModuleProxy,
|
||||
private readonly name: string,
|
||||
private readonly filename: string,
|
||||
private readonly filesize: number,
|
||||
private readonly filecount: number,
|
||||
) {
|
||||
super(moduleProxy.createLogger(name, filename, filesize, filecount));
|
||||
}
|
||||
|
||||
public async trace (message: string): Promise<void> { this.proxy.trace(message); }
|
||||
public async debug (message: string): Promise<void> { this.proxy.debug(message); }
|
||||
public async info (message: string): Promise<void> { this.proxy.info(message); }
|
||||
@ -13,6 +23,10 @@ class RotatingLogger extends ClientProxy<RotatingLoggerProxy> implements spdlog.
|
||||
public async clearFormatters (): Promise<void> { this.proxy.clearFormatters(); }
|
||||
public async flush (): Promise<void> { this.proxy.flush(); }
|
||||
public async drop (): Promise<void> { this.proxy.drop(); }
|
||||
|
||||
protected handleDisconnect(): void {
|
||||
this.initialize(this.moduleProxy.createLogger(this.name, this.filename, this.filesize, this.filecount));
|
||||
}
|
||||
}
|
||||
|
||||
export class SpdlogModule {
|
||||
@ -21,7 +35,7 @@ export class SpdlogModule {
|
||||
public constructor(private readonly proxy: SpdlogModuleProxy) {
|
||||
this.RotatingLogger = class extends RotatingLogger {
|
||||
public constructor(name: string, filename: string, filesize: number, filecount: number) {
|
||||
super(proxy.createLogger(name, filename, filesize, filecount));
|
||||
super(proxy, name, filename, filesize, filecount);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -81,6 +81,11 @@ export class Writable<T extends WritableProxy = WritableProxy> extends ClientPro
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected handleDisconnect(): void {
|
||||
this.emit("close");
|
||||
this.emit("finish");
|
||||
}
|
||||
}
|
||||
|
||||
export class Readable<T extends IReadableProxy = IReadableProxy> extends ClientProxy<T> implements stream.Readable {
|
||||
@ -154,6 +159,11 @@ export class Readable<T extends IReadableProxy = IReadableProxy> extends ClientP
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
protected handleDisconnect(): void {
|
||||
this.emit("close");
|
||||
this.emit("end");
|
||||
}
|
||||
}
|
||||
|
||||
export class Duplex<T extends DuplexProxy = DuplexProxy> extends Writable<T> implements stream.Duplex, stream.Readable {
|
||||
@ -230,4 +240,9 @@ export class Duplex<T extends DuplexProxy = DuplexProxy> extends Writable<T> imp
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
protected handleDisconnect(): void {
|
||||
super.handleDisconnect();
|
||||
this.emit("end");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user