Skip to content

Server crashes if no tweets #1

Open
alexismo opened this Issue Oct 2, 2012 · 3 comments

2 participants

@alexismo
alexismo commented Oct 2, 2012

I'm doing a project and pooling for a nonexisting hashtag. Your server code crashes 1 minute after the 1st connection attempt if no tweet are available after the 1st minute.

Your server implementation doesn't take keepalives in consideration.
https://dev.twitter.com/docs/streaming-apis/connecting#Stalls

Will throw

events.js:45
        throw arguments[1]; // Unhandled 'error' event

and crash.

I'm in the process of writing something that catches keepalives but I'm brand new at node.js so I'm not ready to submit a pull request just yet.

@chovy
Owner
chovy commented Oct 2, 2012

Can you give me an example search that you're using? I will try to reproduce. path: '/1/statuses/filter.json?locations=-122.75,36.8,-121.75,37.8',

@alexismo
alexismo commented Oct 2, 2012

I've been searching for path: /1/statuses/filter.json?track=some_random_hastag_no_one_will_ever_use.

The idea is that this search will not return anything and the browser will close the connection. I got a fix working earlier today. Maybe you can include that.

//stream.js [server side]
result.on('data', function(chunk){
                if(chunk == '\r\n'){//got a keepalive
                    res.write("event: keepalive\n");
                }else{
                    jsonTwitter.feed(chunk);
                }
            });

//main.js [client side]
source.addEventListener('keepalive', function(e){
        //you don't actually have to do anything with this.
        console.log("keepalive received");
    });
@chovy
Owner
chovy commented Oct 10, 2012

Thanks. I will add this fix soon. I am thinking about revamping the entire app to use express.

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.