butterscotchstallion / limnoria-plugins

A smattering of Limnoria plugins I've written
MIT License
14 stars 14 forks source link

SpiffyTitles hangs if presented with a binary file link #111

Open teh-mouses opened 6 years ago

teh-mouses commented 6 years ago

Example - in a channel that my Limnoria bot with SpiffyTitles is running, a user can input the following:

http://217.182.215.117/radio/8010/psy.mp3

This causes the bot to hang for myself and other user, however one user seems to only get a 18 second hang. My workaround was to:

@config supybot.plugins.SpiffyTitles.linkMessageIgnorePattern /(.mp3+)$/

(Note: this does not happen if its just a .mp3 file, only if it's a live streaming mp3)

progval commented 6 years ago

The issue is not that it's binary, it's that it never ends.

The cause is this line:

 request = requests.get(url, headers=headers, timeout=15, allow_redirects=True, verify=verify_ssl_certs)

To quote the doc:

timeout is not a time limit on the entire response download; rather, an exception is raised if the server has not issued a response for timeout seconds (more precisely, if no bytes have been received on the underlying socket for timeout seconds).

cottongin commented 6 years ago

Further from the doc:

By default, when you make a request, the body of the response is downloaded immediately. You can override this behaviour and defer downloading the response body until you access the Response.content attribute with the stream parameter:

tarball_url = 'https://github.com/requests/requests/tarball/master'
r = requests.get(tarball_url, stream=True)

At this point only the response headers have been downloaded and the connection remains open, hence allowing us to make content retrieval conditional

112 fixes this