twitter / twurl

OAuth-enabled curl for the Twitter API
https://developer.twitter.com
MIT License
1.8k stars 301 forks source link

Unexepected "Conn close because of error end of file reached" in stream #165

Open m-thomson opened 3 years ago

m-thomson commented 3 years ago

Describe the bug The following command works as expected, but always terminates with an error "end of file reached" after precisely 5 minutes:

twurl -j -t -d follow=783214 -H stream.twitter.com /1.1/statuses/filter.json > tweets

The error is:

Conn close because of error end of file reached
Traceback (most recent call last):
    24: from /usr/local/bin/twurl:23:in `<main>'
    23: from /usr/local/bin/twurl:23:in `load'
    22: from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/bin/twurl:4:in `<top (required)>'
    21: from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:21:in `run'
    20: from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/cli.rb:40:in `dispatch'
    19: from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/abstract_command_controller.rb:7:in `dispatch'
    18: from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/request_controller.rb:15:in `dispatch'
    17: from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/request_controller.rb:19:in `perform_request'
    16: from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/oauth_client.rb:184:in `perform_request_from_options'
    15: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:1470:in `request'
    14: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:920:in `start'
    13: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:1472:in `block in request'
    12: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:1479:in `request'
    11: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:1517:in `transport_request'
    10: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http/response.rb:165:in `reading_body'
     9: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:1518:in `block in transport_request'
     8: from /Library/Ruby/Gems/2.6.0/gems/twurl-0.9.6/lib/twurl/request_controller.rb:20:in `block in perform_request'
     7: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http/response.rb:204:in `read_body'
     6: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http/response.rb:283:in `read_body_0'
     5: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http/response.rb:264:in `inflater'
     4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http/response.rb:285:in `block in read_body_0'
     3: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http/response.rb:315:in `read_chunked'
     2: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/protocol.rb:201:in `readline'
     1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/protocol.rb:191:in `readuntil'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/protocol.rb:225:in `rbuf_fill': end of file reached (EOFError)

Since it's always after 5 minutes (as measured with the linux time command), it leads me to the obvious conclusion that there is a 5 minute time limit for listening to streams. Is that the case? I can't find anything in the API docs mentioning this.

What is the best way to handle this? Should I just keep re-running the command in a loop?

Expected behavior The command should run indefinitely unless terminated.

Desktop (please complete the following information):

m-thomson commented 3 years ago

I just tried using the V2 endpoint instead and got the same result - termination after 5 minutes due to EOF.

andypiper commented 3 years ago

There should not be a time limit on the stream connection - it is more likely to be a twurl or Ruby issue. Have you tried accessing the streaming endpoints via any other code? There are v2 Filtered stream samples here.