pubnub / javascript

PubNub JavaScript SDK docs https://www.pubnub.com/docs/sdks/javascript
Other
553 stars 401 forks source link

Listener callback is invoked multiple times when message is published and when calling subscribe multiple times #230

Closed puopg closed 2 years ago

puopg commented 3 years ago

Edit: Changed the title to be more representative of the bug at hand.

Seeing some interesting behavior differences after upgrading to version 4.34.0.

Services currently enabled on my key:

Context here is a simple chat application. On message publish, a client receives that message via subscribing to the channel. However, a special situation here is we are subscribed to a channel group.

Affected version: 4.34.0 Unaffected version: 4.33.1

Actual outcome: Multiple invocations to the handler.

Expected outcome: A single invocation to the handler.

samuellawerentz commented 3 years ago

I'm having the similar issue where the handler is invoked multiple times. v4.33.0 is working fine. After updating to v4.34.1 its firing multiple times.

For one message, the handler is firing 4 to 5 times depending on the number of times the pubnub.subscribe() method was called.

puopg commented 2 years ago

I have attached 2 videos, one on 4.33.1 the other using 4.34.0.

Code sandbox also attached. This is a simple counter to visually see how many times the handler is invoked. Notice I only call addListener once, and the only change is calling subscribe.

Codesandbox: https://codesandbox.io/s/dazzling-cannon-y71vi

4.33.1

https://user-images.githubusercontent.com/7741481/144104536-8b4a4693-ac45-48ed-99b8-05f53ceb2803.mov

4.34.0

https://user-images.githubusercontent.com/7741481/144104541-850fddd4-1104-4385-b1d9-ee485be0c2c5.mov

puopg commented 2 years ago

@raipubnub Have you guys noticed this?

ghost commented 2 years ago

Thanks for the detailed report @puopg. We are looking at this and will provide an update once we finish the analysis.

ghost commented 2 years ago

This was a result of a change in superagent that affected chaining the end method. We have a fix ready to go out, should be released soon.

github-actions[bot] commented 2 years ago

@puopg this issue is addressed in v4.34.2

puopg commented 2 years ago

Cool thanks!