moleculerjs / moleculer-channels

Reliable messages for Moleculer services via external queue/channel/topic.
MIT License
72 stars 15 forks source link

Error on reconnection with resubscribeAllChannels #40

Closed DavidP-B closed 1 year ago

DavidP-B commented 1 year ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

Current Behavior

When I'm running moleculer-channels and I got an error, timeout o whatever (an error how cause a reconnection to amqp) when moleculer-channels try to reconnects calls method resubscribeAllChannels. This method always return an error Already tracking active messages of channel XXXX which is located in the method initChannelActiveMessages.

Expected Behavior

No errors and reconnectins as usual.

Temporal solution

I put a try/catch inside resubscribeAllChannels

async resubscribeAllChannels() {
        this.logger.info("Resubscribing to all channels...");
        for (const { chan } of Array.from(this.subscriptions.values())) {
            try {
                await this.subscribe(chan);
            } catch (e) {
                this.logger.error('[resubscribeAllChannels]', e)
            }
        }
    }

Question

Is necessary call the method resubscribeAllChannels, because I make some tests commenting this line and all works well.

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

DavidP-B commented 1 year ago

Also I don't undestand this part. ConnectionCount is used to know if there is a reconnection, but always will be reconnect because after the channel created, you sum 1 to connection count, so isReconnect always return true.

        this.logger.info("AMQP channel created.");

        this.connectionCount++;

        const isReconnect = this.connectionCount > 1;
        if (isReconnect) {
            await this.resubscribeAllChannels();
        }
icebob commented 1 year ago

Also I don't undestand this part. ConnectionCount is used to know if there is a reconnection, but always will be reconnect because after the channel created, you sum 1 to connection count, so isReconnect always return true.

The connectionCount initialized to 0, so first time it will be false (1 > 1 == false).

Could you write repro steps and env?