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

Timeout doesn't close socket connection #139

Open
KrysKruk opened this issue Mar 6, 2019 · 1 comment
Open

Timeout doesn't close socket connection #139

KrysKruk opened this issue Mar 6, 2019 · 1 comment

Comments

@KrysKruk
Copy link

KrysKruk commented Mar 6, 2019

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 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:

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.

@okkez
Copy link
Contributor

okkez commented Mar 11, 2019

Could you show me your code?

The behavior that I expected:

// This will close the logger and its internal socket as soon as possible.
logger.end();

// This will close the logger and its internal socket after send the last message.
logger.end("end", "The last message");

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

No branches or pull requests

2 participants