Skip to content

Commit

Permalink
Handle connection error at start an application
Browse files Browse the repository at this point in the history
This change will reconnect to fluentd, but following error occurs
while reconnecting:

> logger-node/node_modules/fluent-logger/node_modules/readable-stream/lib/_stream_writable.js:491
>   cb();
>   ^
>
> TypeError: cb is not a function
>     at afterWrite (/logger-node/node_modules/fluent-logger/node_modules/readable-stream/lib/_stream_writable.js:491:3)
>     at onwrite (/logger-node/node_modules/fluent-logger/node_modules/readable-stream/lib/_stream_writable.js:483:7)
>     at WritableState.onwrite (/logger-node/node_modules/fluent-logger/node_modules/readable-stream/lib/_stream_writable.js:180:5)
>     at sender.emit (/logger-node/node_modules/fluent-logger/lib/winston.js:46:21)
>     at callbacks.forEach (/logger-node/node_modules/fluent-logger/lib/sender.js:431:23)
>     at Array.forEach (<anonymous>)
>     at _socket.write (/logger-node/node_modules/fluent-logger/lib/sender.js:430:19)
>     at afterWrite (_stream_writable.js:480:3)
>     at process._tickCallback (internal/process/next_tick.js:63:19)

See also nodejs/node#23895

Signed-off-by: Kenji Okimoto <[email protected]>
  • Loading branch information
okkez committed Oct 26, 2018
1 parent 0ae69ff commit 278e40b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class FluentSender {
}

this._push(tag, timestamp, data, callback);
this._connect(() => {
this._connect((error) => {
error && callback && callback(error);
this._flushSendQueue();
});
}
Expand Down Expand Up @@ -206,9 +207,9 @@ class FluentSender {
this._connecting = true;
process.nextTick(() => {
if (this._socket === null) {
this._doConnect(() => {
this._doConnect((error) => {
this._connecting = false;
callback();
callback(error);
});
} else {
if (!this._socket.writable) {
Expand All @@ -232,7 +233,7 @@ class FluentSender {
let errorHandler = (err) => {
if (this._socket) {
this._disconnect();
this._handleEvent('error', err);
this._handleEvent('error', err, callback);
}
};
this._socket.on('error', errorHandler);
Expand Down

0 comments on commit 278e40b

Please sign in to comment.