transports: add "error" event handler for http2 stream

This commit is contained in:
Micooz 2018-07-02 15:11:11 +08:00
parent fd0a51123f
commit d9050efc1d
2 changed files with 13 additions and 1 deletions

@ -19,4 +19,5 @@ export const PROTOCOL_DEFAULT_PORTS = {
'https:': 443,
'ws:': 80,
'wss:': 443,
'h2:': 443,
};

@ -18,9 +18,12 @@ export class Http2Inbound extends Inbound {
this.onReceive = this.onReceive.bind(this);
this.onTimeout = this.onTimeout.bind(this);
this.onClose = this.onClose.bind(this);
// stream
this._stream = this._conn;
this._session = this._stream.session;
this._stream.on('data', this.onReceive);
this._stream.on('error', this.onError);
// session
this._session = this._stream.session;
this._session.on('error', this.onError);
this._session.on('timeout', this.onTimeout);
this._session.on('close', this.onClose);
@ -69,6 +72,10 @@ export class Http2Inbound extends Inbound {
this._session.destroy();
this._session = null;
}
if (this._stream) {
this._stream.close();
this._stream = null;
}
if (!this._destroyed) {
this._destroyed = true;
this.emit('close');
@ -135,6 +142,10 @@ export class Http2Outbound extends Outbound {
this._session.destroy();
this._session = null;
}
if (this._stream) {
this._stream.close();
this._stream = null;
}
if (!this._destroyed) {
this._destroyed = true;
this.emit('close');