Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger write to socket after it died #149

Closed
nbvehbq opened this issue Aug 14, 2019 · 1 comment · Fixed by #151
Closed

Logger write to socket after it died #149

nbvehbq opened this issue Aug 14, 2019 · 1 comment · Fixed by #151

Comments

@nbvehbq
Copy link
Contributor

nbvehbq commented Aug 14, 2019

Look at my log:

Fluentd error { Error: read ETIMEDOUT
     at TCP.onread (net.js:622:25) errno: 'ETIMEDOUT', code: 'ETIMEDOUT', syscall: 'read' }
Fluentd will reconnect after 5 seconds
/app/node_modules/fluent-logger/lib/sender.js:395
    this._socket.write(packet, () => {
                 ^

TypeError: Cannot read property 'write' of null
    at FluentSender._doWrite (/app/node_modules/fluent-logger/lib/sender.js:395:18)
    at FluentSender._doFlushSendQueue (/app/node_modules/fluent-logger/lib/sender.js:389:12)
    at Timeout._flushSendQueueTimeoutId.setTimeout [as _onTimeout] (/app/node_modules/fluent-logger/lib/sender.js:348:18)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5) 

I think this is because _doFlushSendQueue () is called as a callback in setTimeout but we check this._socket early but should in the callback or in the _doWrite

_waitToWrite() {
    if (!this._socket) {
      this._flushingSendQueue = false;
      return;
    }

    if (this._socket.writable) {
      if (this._eventMode === 'Message') {
        this._doFlushSendQueue();
      } else {
        if (this._sendQueueSize >= this._sendQueueSizeLimit) {
          this._flushSendQueueTimeoutId && clearTimeout(this._flushSendQueueTimeoutId);
          this._doFlushSendQueue();
        } else {
          this._flushSendQueueTimeoutId && clearTimeout(this._flushSendQueueTimeoutId);
          this._flushSendQueueTimeoutId = setTimeout(() => {
            // should check socket again or may be check in _doWrite
            this._doFlushSendQueue();
          }, this._flushInterval);
        }
      }
    } else {
      process.nextTick(() => {
        this._waitToWrite();
      });
    }
  }
@okkez
Copy link
Contributor

okkez commented Sep 5, 2019

Could you create a new PR to resolve your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants