fluent / fluent-logger-node

A structured logger for Fluentd (Node.js)
Apache License 2.0
259 stars 83 forks source link

sender: Use `waitToWrite()` to avoid writing to closed socket. #90

Closed fujimotos closed 6 years ago

fujimotos commented 6 years ago

What is this patch?

The current '_doWrite' will push the _doFlushSendQueue callback to the event loop queue after a successful write.

The problem is that the socket might be closed by the time the enqueued _doFlushSendQueue callback gets called, and in this case, it would just crash hard with the following error:

TypeError: Cannot read property 'write' of null

We can avoid this issue by enforcing the logger to call the waitToWrite routine before _doFlushSendQueue.

Note

This patch fixes the issue reported by #83.

okkez commented 6 years ago

Thanks!