kubemq-io / kubemq-js

Apache License 2.0
9 stars 7 forks source link

Fixed RPC subscribe reconnection and incorrect closing handling. #7

Closed usein-abilev closed 4 weeks ago

usein-abilev commented 5 months ago

This PR fixes #1.

Previously, the subscribe method of the QueriesClient class had incorrect handling of close and unsubscribe events. The event received from stream.on("close") did not lead to any consequences. If the connection to KubeMQ was lost, then reconnection could not occur, because isClosed was always false.

I also moved the subscription from cycle-dependent to event mode, so as not to once again load the event loop with unnecessary functions deferred every second.

Here is a bug, onClose was not called on the other side: https://github.com/kubemq-io/kubemq-js/blob/main/src/queries.ts#L296C1-L304C12

let onClose = new TypedEvent<void>();
stream.on('close', () => {
  onClose.emit();
});
resolve({
  onClose: onClose,
  stream: stream,
});
kubemq commented 4 weeks ago

Hi, I'm closing this PR as we have released a new version that handled this situation