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', () =>


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.