redouane59 / twittered

Twitter API client for Java developers
Apache License 2.0
236 stars 64 forks source link

How to detect network issues/IP changes for filtered streams? #305

Open 125m125 opened 2 years ago

125m125 commented 2 years ago

Hello,

I am using twittered to read a filtered stream from a network connection where I get a new IP at least once a day. With the default settings, the connection stays open without an exception after the IP changes, but is not receiving any new tweets.

I tried to set the connect and read timeout for the JDKHttpClient, but that doesn't seem to recognize network problems for the streams. Even if I disconnect my network for more than a minute, the connection stays open without an exception.

Is there any recommended way to detect these problems to be able to reconnect the stream?

Minimal example (you will have to disconnect your network/get a new IP manually): https://github.com/125m125/twitteredtimeout/blob/main/src/main/java/de/_125m125/twitteredtimeout/Main.java

For my project I worked around this by checking every 30 seconds, if I received a heartbeat/tweet in the last interval. If not, I manually restart the connection. But even calling stopStream on the zombie connection blocks indefinitely on IP change or until the connection is restored, if it was interrupted without IP change (I now close the existing connection in a new thread to avoid the blocking).

redouane59 commented 2 years ago

Hello @125m125 , I'm sorry but i don't have any idea about how to solve it, this is something I don't really manage well. Hope someone else will see this issue and will be able to bring some elements :(