gotwi icon indicating copy to clipboard operation
gotwi copied to clipboard

Filtered Stream Timeout

Open Typositoire opened this issue 1 year ago • 1 comments

So I read this: https://github.com/michimani/gotwi/issues/258

And it might just be me, I'm developing as a hobby, but the fact that Twitter sends a keep-alive signal every 20 sec, should the client NOT timeout? I feel that putting timeout: 0 is dangerous. The client should timeout after 30 sec of idling but not if it receives events every 20 seconds.

From Twitter's doc:

Keep-alive signals
At least every 20 seconds, the stream will send a keep-alive signal, or heartbeat in the form of an \r\n carriage return through the open connection to prevent your client from timing out. Your client application should be tolerant of the \r\n characters in the stream.

If your client properly implements a read timeout on your HTTP library, your app will be able to rely on the HTTP protocol and your HTTP library to throw an event if no data is read within this period, and you will not need to explicitly monitor for the \r\n character.

This event will typically be an exception being thrown or some other event depending on the HTTP library used. It is highly recommended to wrap your HTTP methods with error/event handlers to detect these timeouts. On timeout, your application should attempt to reconnect.

Typositoire avatar Dec 03 '22 15:12 Typositoire