x-cubed / event-store-client

JS client library for connecting to Event Store over TCP/IP
The Unlicense
71 stars 24 forks source link

Client connection lost during heartbeat timeout #17

Closed amri closed 7 years ago

amri commented 8 years ago

Hi,

I've been investigating issue where my js code intermittenly stop pushing event to eventstore. Once I put some logging i found these:

[PID:01424:012 2016.08.13 15:07:30.341 TRACE TcpConnectionManager] Closing connection 'external-normal' [127.0.0.1:61047, L127.0.0.1:1113, {7c3c6a87-ec80-404c-b0f5-916f7ef81e72}] cleanly. Reason: HEARTBEAT TIMEOUT at msgNum 3742004
[PID:01424:012 2016.08.13 15:07:30.341 INFO  TcpConnection       ] ES TcpConnection closed [15:07:30.341: N127.0.0.1:61047, L127.0.0.1:1113, {7c3c6a87-ec80-404c-b0f5-916f7ef81e72}]:Received bytes: 284729333, Sent bytes: 6448674876
[PID:01424:012 2016.08.13 15:07:30.341 INFO  TcpConnection       ] ES TcpConnection closed [15:07:30.341: N127.0.0.1:61047, L127.0.0.1:1113, {7c3c6a87-ec80-404c-b0f5-916f7ef81e72}]:Send calls: 3741924, callbacks: 3741924
[PID:01424:012 2016.08.13 15:07:30.341 INFO  TcpConnection       ] ES TcpConnection closed [15:07:30.341: N127.0.0.1:61047, L127.0.0.1:1113, {7c3c6a87-ec80-404c-b0f5-916f7ef81e72}]:Receive calls: 3742005, callbacks: 3742004
[PID:01424:012 2016.08.13 15:07:30.341 INFO  TcpConnection       ] ES TcpConnection closed [15:07:30.341: N127.0.0.1:61047, L127.0.0.1:1113, {7c3c6a87-ec80-404c-b0f5-916f7ef81e72}]:Close reason: [Success] HEARTBEAT TIMEOUT at msgNum 3742004

I found in .NET client library have the functionality:

connectionSettingsBuilder.KeepReconnecting();
connectionSettingsBuilder.KeepRetrying();

Is there a workaround for this issue ? or should I reconnect when onError / onClosed event called ?

coreyperkins commented 8 years ago

I reset my connection onError (via the options) then hook my subscription back up. It works fine, but I would also like the ability to have this lib do that for me.

x-cubed commented 8 years ago

Feel free to submit a pull request to implement support for this. All contributions are gratefully received.

amri commented 8 years ago

@coreyperkins how do you reconnect onError ?

coreyperkins commented 8 years ago

@amri In my options I define the onError handler like so.

var sourceOptions = {
  host: sourceConfig.eventStore.address,
  port: sourceConfig.eventStore.port,
  debug: sourceConfig.debug,
  credentials: sourceConfig.eventStore.credentials,
  streamId: sourceConfig.eventStore.stream,
  onError: function(err) {
    console.error('There was an error connecting to the source es!');
    console.error(err);
    console.error(err.stack);

    subscribe();
  }
};

Then in the subscribe function I simply make a call to connection.subscribeToStreamFrom providing the last check point I successfully got to.

Enjoy!