Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda