Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
Firebase Realtime Database concurrent connections reliability

I count the concurrent connections as follows:

onValue(ref(db, '.info/connected'), snapshot => {
            
    if (snapshot.val()) {

        let con = push(ref(db, 'concurrent'), { connected: moment().format('DD/MM/YYYY HH:mm') })

        onDisconnect(con).remove()

    }
}) 

However, when I check the database, I see connections from several days ago:

enter image description here

Does that mean that users have had inactive browser tabs since several days ago? Am I doing something wrong? Is the onDisconnect() function 100% reliable?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

firebaser here

Do you have security rules on the concurrent path that require the user to be authenticated by any chance? Because there's an open issue around that, which has been causing problems for more people recently.

Aside from that we haven't seen reliability issues in onDisconnect handling recently, so we'd need to see more information about the lingering connections (a stand-alone repro would be good).

about 4 years ago · Juan Pablo Isaza Report

0

Reading the issue, it seems that if the tab is inactive for more than an hour, the token expires. If the tab is active again, Firebase client reconnects and gets a new token.

To remove the path in case of token expiration (idle tab):

const onIdleTabGoOffline = (ms) => {

    let timer

    document.addEventListener('visibilitychange', () => {

        if(document.hidden){

            timer = setTimeout(() => goOffline(db), ms)

        }
        else{

            clearTimeout(timer)

            goOnline(db)

        }

    })

} 

Finally:

onValue(ref(db, '.info/connected'), snapshot => {
    
    if (snapshot.val()) {

        let con = push(ref(db, 'concurrent'), { connected: moment().format('DD/MM/YYYY HH:mm') })

        onDisconnect(con).remove()

        onIdleTabGoOffline(59 * 60 * 1000)

    }
}) 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!