- Ably FAQs
- Realtime API and client libraries
- Common issues
-
Account billing and packages
-
General
-
Realtime API and client libraries
-
Troubleshooting
-
Channels
-
REST API and client libraries
-
Ably error codes
-
Account and app setup and configuration
-
Ably architecture, transports, and security
-
Performance and Redundancy
-
Push Notifications
-
Reactor Queues, Events and Firehose
-
Migrating to Ably from an existing service
-
API Streamer
-
Connections
Why is my subscribe listener being called multiple times per message?
The most common reason for this is that you have called subscribe() multiple times. Every time it is called it adds a new message listener, even if that same listener is already registered for that event; when a message is received, every registered listener will be called with it.
The most common reason for subscribe() being called multiple times is if it called it from an event listener that can be called more than once. For example, the following code:
ably.connection.on('connected', () =>
ably.channels.get('foo').subscribe(listener)
);
will add a new listener every time the client library reconnects to Ably (e.g. following clientside network issues), meaning listeners will build up over time. The solution to this is to use once instead of on, which is only called once, or alternatively to just move the subscribe() call to outside the connected listener.