title: Firebase Realtime database write operations stuck at "pending" state with web sdk
body: <p>We have a subtle bug with Firebase Realtime database write operations.</p>
  <p>Client(browser) is connected to database with websocket and sends the write operations but doesn't get any reply back from Firebase which keeps the operation in &quot;pending&quot; state. See the network and console logs below.</p>
  <p><img src="https://i.stack.imgur.com/vb4XI.png" alt="Client network trace" /></p>
  <p><img src="https://i.stack.imgur.com/GoKOl.png" alt="Some sample write commands" /></p>
  <p>So far, we could only overcome the issue by stopping the connection to database and re-connecting with:</p>
  <pre class="lang-js prettyprint-override"><code>firebase.database().goOffline();
  firebase.database().goOnline();
  </code></pre>
  <p>As you can see in the below screenshot operations continue after <code>goOnline</code> and we got permission denied errors as expected.</p>
  <p><img src="https://i.stack.imgur.com/2S5s1.png" alt="Operations continue after reconnection" /></p>
  <p>However, we are not able to detect the condition reliably. <code>.info/connected</code> still shows as connected. Websocket connection is still there. Only indication is long-running write operations.</p>
  <p>The issue usually happens on long sessions on mobile where user has closed their browser to background (haven't quit but just sent it to background) and reopened the browser to continue application. But it is not specific to mobile, we have seen the issue on desktop as well.</p>
  <p>My question is why this occurs and how could we fix it? Or if not, how can we reliably detect the issue, so that we can go offline and online?</p>