Skip to content

Disconnected after a while #1

Closed
niuage opened this Issue Mar 21, 2011 · 14 comments

6 participants

@niuage
niuage commented Mar 21, 2011

Hey,

I wrote a campfire bot based on node-campfire, and it works well.
But after a few minutes, it stops listening to the room.
I modified the Room.prototype.listen function to listen again on "end":
response.on("end", function() {
// new request to listen to the room
})

Is this the best way to handle this? How would you do it?

Thanks!

@boucher
boucher commented May 5, 2011

Same question.

@erunion
erunion commented May 24, 2011

Have been having the same thing happen, it just seems to disconnect after an hour or so of being jacked in. Not really sure what's going on since it isn't erroring out, just a silent disconnect.

@niuage
niuage commented May 25, 2011

"Our servers will try to hold the streaming connections open indefinitely. However, API clients must be able to handle occasional timeouts or disruptions."
I stayed with this (re-listening on "end"), and if I remember correctly, it worked pretty well.

Campfire.Room.prototype.listen = function(callback) {
    // ...
    options = {
        //...
    }
    var listen_to = function(options) {
        system.puts("LISTEN TO " + room.name + " (id=" + room.id + ")");
        room.join(function() {
            req = campfire.http.request(options, function(response) {

                response.on('data', function(chunk) {
                    // ...
                });

                response.on("end", function(data) {
                    system.puts("LEAVE FROM " + room.name + " (id=" + room.id + ")");
                    listen_to(options);
                });
            }).end();
        })
    }

    listen_to(options);
},
@tristandunn
Owner

Thanks for the reports and the quote about clients needing to handle timeouts. I plan to fix the issue this weekend. Sorry for the delay.

@tristandunn tristandunn was assigned May 29, 2011
@tristandunn
Owner

I was unable to recreate the issue this weekend, as in I was never disconnected after hours of having a connection open. I'm going to look into adding unit and/or integration tests to ensure it's actually fixed.

@erunion
erunion commented Jun 1, 2011

Usually the connection never dies, but I've noticed if in something like Propane Campfire starts freaking out and takes a while to send me new messages, that usually the connection that I've opened with node-campfire has been killed.

Wrote niuage's fix into my fork and it seems to be doing the trick so far.

jonursenbach/node-campfire@471f204

@erunion
erunion commented Jun 22, 2011

Just an update on this, that fix I put into my fork that niuage wrote didn't end up working so I've stopped using it. Have updated to HEAD and am still having this issue. My bot lost its connection and died after being connected for 4 days.

@tristandunn
Owner

I'm leaning towards not trying to fix this if it can stay connected for four days.

I feel like a better option would be to monitor it with something like forever. I can add a note to the README or something explaining this. Does that seem reasonable?

@boucher
boucher commented Jun 22, 2011

This issue isn't the whole script failing though, just the Campfire connection being lost. So to use it with forever you'd have to actually kill the script if it detects a connection failure.

@tristandunn
Owner

Sorry, good point. I thought it was throwing an error when it disconnected, but that wouldn't make sense as the request is just ending.

Need to finish my coffee before I comment.

@roykolak

Hey there, just wanted to chime in. Experiencing the same problem at the moment with a custom built bot. Mine was supported by forever, not responding after a few hours, and I was really puzzled. Thanks for the tip monitoring 'end', will try that.

@jasonroelofs

So a quick note about listening for "end" as is here in this issue: I almost got my campfire account suspended because my bot got into a state where it was infinitely looping the "end" event and basically trying to reconnect a few hundred times a second...

I will need to make that reconnect logic a bit smarter, wait a few seconds, and exit entirely if a few retries simply don't work, letting forever restart the entire client.

@tristandunn
Owner

It'd probably be worth implementing node-retry into it. Any opinions on it?

@tristandunn
Owner

Sorry for taking forever to fix this.

Unfortunately I still haven't recreated the scenario myself. Could someone try it out in master and let me know before I release a new version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.