node-twitter icon indicating copy to clipboard operation
node-twitter copied to clipboard

Stream get disconnected somehow without any errors

Open pcolazurdo opened this issue 11 years ago • 18 comments

I have a node.js app which is listening while the application is alive. Somehow it seems like the stream get disconnected but I can't seem to find any reason, neither an error. Any suggestion about how to manage this?

twit.stream('user', {track:'pcolazurdo'}, function(stream) { stream.on('data', function(data) { console.log(util.inspect(data)); if (typeof data.id_str !== 'undefined') insert_doc(data); }); stream.on('error', function(data) { console.log(util.inspect(data)); }); });

(No error is logged either)

Thanks in advance, Pablo

pcolazurdo avatar Dec 16 '14 16:12 pcolazurdo

You probably can't authorize because your system clock is out of sync.

nullzion avatar Feb 17 '15 22:02 nullzion

happens to me for a while now, never raised an issue. +1

mhdatie avatar Feb 18 '15 19:02 mhdatie

I couldn't find the error (clock out of sync doesn't seem to be the problem) ... I've applied an awful hack which is to restart the server whenever I don't see any update in x mins.

pcolazurdo avatar Feb 18 '15 23:02 pcolazurdo

See if you can get on('done') event output, there should be response somewhere in it with status code.

nullzion avatar Feb 20 '15 18:02 nullzion

Hello, i'm not shure if this is related to this issue, but i experience 'stalled' connection when streaming API (filter/statuses endpoint). When having a look at the sources i could not find the code, that is handling the keep-alive packets delivered by the API (see dev.twitter.com 'Stalls'). If i got it right, in parser.js line 36 json = this.buffer.slice(0, index); returns an empty array if this.buffer.match(/^\r\n$/). Thus, nothing will happen on receiving the keep-alive. My workaround for now is, to patch parser.js and emit a 'keep-alive' event and monitor the heartbeat in my client code. I didn't have the chance to perform a long-running test, but it seems to work. My workaround code:

var heartbeat_expr = new RegExp(util.format('^%s$', Parser.END), 'g');                          
if (this.buffer.match(heartbeat_expr)) {                                                         
  this.emit('keep-alive');                                                                      
}

Since i'm not entirely sure, if i am right with my analysis, it would be nice, to check, if and how the keep-alive newlines are handled.

g3org avatar Feb 23 '15 09:02 g3org

i have same issue.

My Code is :

var Twitter = require('twitter');
var client = new Twitter({
  consumer_key: 'xxx',
  consumer_secret: xxx',
  access_token_key: 'xxx',
  access_token_secret: 'xxx',
});

// Stream
client.stream('statuses/filter', {track: 'america'}, function(stream) {
  stream.on('data', function(tweet) {
    console.log(tweet.text);
    console.log("Get Success !!!");
  });

  stream.on('error', function(error) {
    console.log("Error in stream");
    console.log(""+error);
  });
});

it will not get error connection close directly on linux machine. and my credential is correct. i was tested same credential for post data on twitter.

prashantgbhangre avatar Mar 03 '15 10:03 prashantgbhangre

+1

a-iasevoli avatar May 25 '15 23:05 a-iasevoli

Doing some playing around and I think I'm seeing this issue on GET statuses/sample:

It will always run for about ~30s before exiting. I see nothing in the twitter docs mentioning a 30s limit so I'm guessing it's this issue? Related to #92 ?

cmawhorter avatar Jun 23 '15 15:06 cmawhorter

+1

antoniosou avatar Jul 15 '15 16:07 antoniosou

I am able to capture the 'end' event.

client.stream('statuses/filter', {track: 'javascript'}, function(stream) {
  stream.on('data', function(tweet) {
    console.log(tweet.text);
  });

  stream.on('error', function(error) {
    throw error;
  });
  stream.on('end', function(reason) {
        console.log('end');
        console.log(reason);
  });
});

When would this be emitted?

aswins avatar Oct 12 '15 05:10 aswins

I get the 'end' when I try to run this from the current master. When I run this, it quits immediately. Then I went back to [0b69ff0] ie.(v1.2.5), This runs without issues.

aswins avatar Oct 12 '15 07:10 aswins

Any update / resolution on this? @aswins @desmondmorris

alexellis avatar Jul 02 '16 21:07 alexellis

+1

seanbrodie avatar Jul 18 '16 12:07 seanbrodie

+1

ivanbacher avatar Oct 14 '16 09:10 ivanbacher

+1

anjanaaa avatar Oct 09 '17 09:10 anjanaaa

+1

emersonqueiroz avatar Jun 28 '18 20:06 emersonqueiroz

+1

ericycoding avatar Oct 26 '18 19:10 ericycoding

This library is no longer maintained.

twitter-lite has streaming support as well, and is actively maintained.

dandv avatar Dec 18 '18 21:12 dandv