Firebase web - close connection to the realtime database

11,947

Solution 1

Try this-

firebase.initializeApp(config);

// Kill this firebase app.
firebase.app().delete().then(function() {
  firebase.initializeApp(newConfig);
});

goOffline() will close connection but Firebase will continue to work locally and the app will remain in memory.

Solution 2

Try using:

firebaseRef.off();

This will end your connection with firebase and stop communicating with the database.

Solution 3

For JSv9, as @Frank van Puffelen said, calling goOffline(db)

Disconnects from the server (all Database operations will be completed offline).

Quoted from Official Document.

Note that the db here is a Database instead of a DatabaseRef. Maybe you didn't call it in the correct way.

I looked up for this for this jest error: A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. (I made a note here in my knowledgebase.) And adding a goOffline(db) in afterAll() actually solved it.

Share:
11,947
Sahar Millis
Author by

Sahar Millis

Yep I'm a Data Scientist. Specializes in AI - Machine Learning and Deep Learning. Working on my Master's Degree. Excellent in the field of Software and Algorithms. ... I believe we can do anything with a pizza and a beer next to the keyboard... ;)) "Always Question Your Data" SM

Updated on June 08, 2022

Comments

  • Sahar Millis
    Sahar Millis about 2 years

    I'm using Firebase on the web, with Javascript.
    how can I close the connection to the realtime DB ?

    var config = {....};
    firebase.initializeApp(config);
    
    // get the firebase DB reference
    var db = firebase.database().ref();
    
    //doing something
    db.push(....);
    
    // close the firebase connection ???
    db.close() || firebase.disconnect() || or something like that...
    

    Tried lots of functions - goOffline() , close() , ect.
    But nothing does the trick.

    Any help would be appreciated... tnx mates