0

When i send a request to "check-status1" i am able to get data at "fire-test" location. Once i send a request to "check-status2" i get an exception (Exception: Error: Can't set headers after they are sent). After that if i again send request to check-status1 i am not getting any response in success callback and even it is not entering into falilure callback but node able to serve for other non firebase related stuff (like email sending ).

Why firebase not responding after getting the above exception?

app.get('/check-status1', function (req, res) {      
    FirebaseRef.child('fire-test').once('value', function (snapShot) {
        res.send(JSON.stringify(snapShot.val()));
    }, function (err) {
        console.log(err);
    });
});


app.get('/check-status2', function (req, res) {

    FirebaseRef.child('fire-test').once('value', function (connectedSnap) {
        console.log(connectedSnap.val());
        res.send(JSON.stringify(connectedSnap.val()));
    }, function (err) {
        console.log(err);
    });
    res.end(JSON.stringify({"success":true}));      

});
Ashok
  • 661
  • 6
  • 17
  • Well, try and find out *why* the error is happening. It looks like you're not handling the condition of not being able to access Firebase correctly, but I'd be guessing since you don't post any code. – robertklep May 28 '13 at 09:07
  • I got the error. When i get this error i am trying to create new reference to Firebase even it is also not working. – Ashok May 28 '13 at 09:16
  • If you don't post any of your code, it's very hard for people to help you solve the problem... – robertklep May 28 '13 at 10:19
  • Please post as much code as practical to help us generate ideas. Also, try adding an additional function to capture errors: `FirebaseRef.child('users').once('value', function(snap) {}, function(error) { /* log the error here */ }` – Kato May 28 '13 at 16:30
  • @Kato i edited the question. I hope you can understand my problem. – Ashok May 29 '13 at 09:54
  • @Ashok (removed my answer because it's not useful) I think it might be a bug in the Firebase module. However, it's hard to debug because the module is only distributed [as minified source](https://github.com/firebase/firebase-node/blob/master/lib/firebase-node.js) (which is very bad practice IMO...) – robertklep May 29 '13 at 11:14
  • @rebertklep that's not accurate, there is a [debug version](https://cdn.firebase.com/v0/firebase-debug.js) of the code as well – Kato May 29 '13 at 14:00
  • "Can't set headers after they are sent" is an error you will see when you attempt to create a new HTTP header after the data has already been delivered to the client [1](http://stackoverflow.com/questions/7042340/node-js-error-cant-set-headers-after-they-are-sent) [2](http://stackoverflow.com/questions/15996402/cant-set-headers-after-they-are-sent); and, thus, the error is unlikely to be Firebase related, though anything is possible. Can you please include a complete example that we can run? The code above is but a snip and does not include all the relevant data needed to spot the error. – Kato May 29 '13 at 14:13
  • @Kato Intentionally i kept that error code. Once if i got that error(Can't set headers after they are sent) node is not able to interact with firebase but it is serving other requests which doesn't have any interaction with firebase. If i restart node server everything is fine. – Ashok May 29 '13 at 14:35
  • Okay, well I think we're going to need a way to reproduce it to get any farther troubleshooting. :) – Kato May 29 '13 at 18:40

0 Answers0