Skip to content

Commit

Permalink
fix: print err if encoder/decoder error (#101)
Browse files Browse the repository at this point in the history
pump will destroy socket, if destroy socket in cb again.
it will do nothing and error whil not print.
  • Loading branch information
killagu authored Sep 6, 2022
1 parent 1921e7d commit 50b8500
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
tar xf zookeeper-3.4.6.tar.gz
mv zookeeper-3.4.6/conf/zoo_sample.cfg zookeeper-3.4.6/conf/zoo.cfg
./zookeeper-3.4.6/bin/zkServer.sh start
npm i -g npminstall && npminstall
npm i -g npminstall@5 && npminstall
- name: Continuous Integration
run: npm run ci
Expand Down
9 changes: 6 additions & 3 deletions lib/server/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class RpcConnection extends Base {
this._decoder.on('heartbeat', hb => { this._handleHeartbeat(hb); });
// @refer https://nodejs.org/en/docs/guides/backpressuring-in-streams/
pump(this._encoder, this.socket, this._decoder, err => {
this.close(err);
if (err && err.code !== 'ECONNRESET') {
// error may throw by encoder/decoder, so should print the stack
this.logger.warn('[RpcConnection] error occured on socket: %s, errName: %s, errMsg: %s', this.remoteAddress, err.name, err.stack);
}
});

this._closed = false;
Expand Down Expand Up @@ -99,8 +102,8 @@ class RpcConnection extends Base {

close(err) {
if (this.isClosed) return Promise.resolve();

this.socket.destroy(err);
this._decoder.end();
this._encoder.destroy(err);
return this.await('close');
}

Expand Down

0 comments on commit 50b8500

Please sign in to comment.