title: Firebase Realtime Database Uncaught RangeError: Maximum call stack size exceeded
body: <p>Recently I have been working on a project using Firebase Realtime Database. Till now everything was going very well, but suddenly the code broke from the part of my code which I wrote during the start of the project.</p>
  <p>[Here is the snippet from my code. I am using this algorithm to update the code in the database.]</p>
  <pre><code>export const addUserToProject = async (project_id, user) =&gt; {
  await firebase.database().ref('projects/' + project_id).once('value', snapshot =&gt; {
      const numUsers = snapshot.child('numUsers').val()
      if (!snapshot.child('users').exists()) {
          snapshot.ref.child('users').set([user])
          snapshot.ref.child('numUsers').set(numUsers + 1)
      }
      if (snapshot.child('users').exists()) {
          const users = snapshot.child('users').val();
          snapshot.ref.child('users').set([user, ...users]) // This line
          snapshot.ref.child('numUsers').set(numUsers + 1)
      }
  }, error =&gt; {
      throw new Error(error.message)
  })}
  </code></pre>
  <p>When the function is called, it make non-stop recursive calls at the highlighted lines and after a few seconds, it shows the following error:</p>
  <pre><code>index.esm.js:649 Uncaught RangeError: Maximum call stack size exceeded
  at syncTreeRemoveEventRegistration (index.esm.js:9897)
  at repoRemoveEventCallbackForQuery (index.esm.js:11464)
  at onceCallback (index.esm.js:13242)
  at CallbackContext.onValue (index.esm.js:12274)
  at index.esm.js:13118
  at exceptionGuard (index.esm.js:638)
  at eventListRaise (index.esm.js:11082)
  at eventQueueRaiseQueuedEventsMatchingPredicate (index.esm.js:11057)
  at eventQueueRaiseEventsForChangedPath (index.esm.js:11044)
  at repoSetWithPriority (index.esm.js:11346)
  at set (index.esm.js:12990)
  at Reference.set (index.esm.js:14745)
  at addProjectToUser.js:15
  at valueCallback (index.esm.js:14526)
  at onceCallback (index.esm.js:13241)
  at CallbackContext.onValue (index.esm.js:12274)
  at index.esm.js:13118
  at exceptionGuard (index.esm.js:638)
  at eventListRaise (index.esm.js:11082)
  at eventQueueRaiseQueuedEventsMatchingPredicate (index.esm.js:11057)
  at eventQueueRaiseEventsForChangedPath (index.esm.js:11044)
  at repoSetWithPriority (index.esm.js:11346)
  at set (index.esm.js:12990)
  at Reference.set (index.esm.js:14745)
  at addProjectToUser.js:15
  at valueCallback (index.esm.js:14526)
  at onceCallback (index.esm.js:13241)
  at CallbackContext.onValue (index.esm.js:12274)
  at index.esm.js:13118
  at exceptionGuard (index.esm.js:638)
  at eventListRaise (index.esm.js:11082)
  at eventQueueRaiseQueuedEventsMatchingPredicate (index.esm.js:11057)
  at eventQueueRaiseEventsForChangedPath (index.esm.js:11044)
  at repoSetWithPriority (index.esm.js:11346)
  at set (index.esm.js:12990)
  at Reference.set (index.esm.js:14745)
  at addProjectToUser.js:14
  at valueCallback (index.esm.js:14526)
  at onceCallback (index.esm.js:13241)
  at CallbackContext.onValue (index.esm.js:12274)
  at index.esm.js:13118
  at exceptionGuard (index.esm.js:638)
  at eventListRaise (index.esm.js:11082)
  at eventQueueRaiseQueuedEventsMatchingPredicate (index.esm.js:11057)
  at eventQueueRaiseEventsForChangedPath (index.esm.js:11044)
  at repoSetWithPriority (index.esm.js:11346)
  at set (index.esm.js:12990)
  at Reference.set (index.esm.js:14745)
  at addProjectToUser.js:14
  at valueCallback (index.esm.js:14526)
  </code></pre>
  <p>Any help would be very grateful.</p>
  <p>Thanks in Advance.</p>