SimformSolutionsPvtLtd / react-native-audio-waveform

React Native component to show audio waveform with ease in react native application ✨
MIT License
141 stars 22 forks source link

Numerous amount of promises leaking causing `Excessive number of pending callbacks: 501` errors [Android] #106

Closed dprevost-LMI closed 1 month ago

dprevost-LMI commented 1 month ago

The Android code has multiple places without a guarantee of resolving the promise. This PR provides numerous fixes for issues I encountered while playing audio in the list. Most of them are just simple code review refactoring.

For example, just opening one audio file made three promises hang, and each call to seekToPlayer a promise leaks. So, just clicking 500 times on the waveform triggers the below error:

Excessive number of pending callbacks: 501. Some pending callbacks that might have leaked by never being called from 
native code: {"55":{"module":"AudioWaveform","method":"setPlaybackSpeed"},"89":
{"module":"AudioWaveform","method":"setPlaybackSpeed"}

Another case I encounter is when having multiple audio players in the last and start playing them. After playing around 10 of them, a similar error appears.

Using the below after wraping async function with it, we can see how many promises are not returning:

let nbOfPromises = 0;

const logPromise = async (promise: any, promiseName: string) => {
  try {
    nbOfPromises++;
    console.log(`Promise ${promiseName} has been called`);
    return await promise();
  } finally {
    nbOfPromises--;
    console.log(`Promise ${promiseName} has finished`);
    if (nbOfPromises > 0)
      console.log(`Number of promises remaining: ${nbOfPromises}`);
  }
};