fluent / fluent/fluent-logger-node

Timeout doesn't close socket connection

Open
#139 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
258
Forks
82
PR merge metrics
No merged PRs in 30d

Description

Hi guys!

I was struggling some time on automatically closing the `fluent` socket when idling.
I wanted to emit some logs and then let the process to exit. That never happened, because the internal `fluent` socket was still open.
I could just call the `end()` function, but that was not an option for me.

After studying [Node.js socket documentation](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback) I found out that calling `socket.setTimeout` doesn't really close the connection, only emits a `timeout` event which then needs to be handled by the developer.

That was of course my lack of knowledge, but I'm thinking how `fluent-logger-node` could be improved here.

What do you guys think of emitting the `timeout` event on the `FluentSender` and let developer call `end()` method later?

The other option would be adding e.g. `autoClose` or `closeOnTimeout` boolean flags to the `FluentSender` constructor.

Also I figured that in `tls` mode, the given `timeout` is not set on the `socket` (even `{ tlsOptions: { timeout: 3 } }` doesn't work).

For now I use a workaround:
```javascript
fluent.on('connect', () => {
fluent._socket.setTimeout(1000)
fluent._socket.on('timeout', () => {
fluent.end()
})
})
```

Thanks for feedback. Sorry if I misunderstood the problem and there is some other way to handle that.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.