src: fix crush when onConnected() is triggered after ss-base destroyed
This commit is contained in:
parent
bbc1ce990c
commit
5d0fc5ac6e
@ -185,7 +185,9 @@ export default class SsBasePreset extends IPresetAddressing {
|
||||
port: port,
|
||||
// once connected
|
||||
onConnected: () => {
|
||||
next(Buffer.concat([data, this._pending]));
|
||||
if (this._pending !== null) {
|
||||
next(Buffer.concat([data, this._pending]));
|
||||
}
|
||||
this._isHeaderRecv = true;
|
||||
this._isConnecting = false;
|
||||
this._pending = null;
|
||||
|
@ -318,12 +318,16 @@ export class TcpOutbound extends Outbound {
|
||||
}
|
||||
this._socket.on('connect', () => {
|
||||
if (typeof onConnected === 'function') {
|
||||
onConnected((buffer) => {
|
||||
if (buffer) {
|
||||
const type = this._config.is_client ? PIPE_ENCODE : PIPE_DECODE;
|
||||
this.ctx.pipe.feed(type, buffer, { cid: this.ctx.proxyRequest.cid, host, port });
|
||||
}
|
||||
});
|
||||
try {
|
||||
onConnected((buffer) => {
|
||||
if (buffer) {
|
||||
const type = this._config.is_client ? PIPE_ENCODE : PIPE_DECODE;
|
||||
this.ctx.pipe.feed(type, buffer, { cid: this.ctx.proxyRequest.cid, host, port });
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error(`[${this.name}] [${this.remote}] onConnected callback error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
this.ctx.pipe.broadcast(null, { type: CONNECTED_TO_REMOTE, payload: { host, port } });
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user