pinojs / pino-socket

🌲 A transport for sending pino logs to network sockets
43 stars 14 forks source link

Backoff strategy should be instantiated only once and reset when the connection is established again #69

Closed ggrossetie closed 2 years ago

ggrossetie commented 2 years ago

Currently, we instantiate a new Backoff and BackoffStrategy every time reconnect is called via backoff.fibonacci which is equivalent to new Backoff(new FibonacciBackoffStrategy(options)).

https://github.com/pinojs/pino-socket/blob/4d79b0e1f201db0ae72347c68be0cdfdafad4346/lib/TcpConnection.js#L95

This is problematic because when the socket is closed (for instance when we get a ECONNREFUSED) the backoff strategy is instantiated again and, as a result, the backoff value will be the initial value (defeating the purpose of using an incremental backoff).

jsumners commented 2 years ago

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

ggrossetie commented 2 years ago

@jsumners sure, here's the pull request: https://github.com/pinojs/pino-socket/pull/71