nodejs-stream icon indicating copy to clipboard operation
nodejs-stream copied to clipboard

Server crashes if no tweets

Open alexismo opened this issue 13 years ago • 3 comments

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.

alexismo avatar Oct 02 '12 12:10 alexismo

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',

ralyodio avatar Oct 02 '12 20:10 ralyodio

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");
    });

alexismo avatar Oct 02 '12 21:10 alexismo

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

ralyodio avatar Oct 10 '12 05:10 ralyodio