coleifer / micawber

a small library for extracting rich content from urls
http://micawber.readthedocs.org/
MIT License
635 stars 91 forks source link

'IOError: [Errno 11] Resource temporarily unavailable' with Peewee sample blog app #59

Closed keybits closed 8 years ago

keybits commented 8 years ago

I get the error shown below when I run the Peewee sample blog app from here: https://github.com/coleifer/peewee/tree/master/examples/blog

Specifically this happens when Micawber tries to display a post with links that need converting to embeds (e.g. a YouTube video link).

I've been able to reproduce this reliably with different links (e.g. Vimeo links instead of YouTube) and different browsers. It doesn't always happen immediately, but if you click around to view the posts with embeds, then return to the index page, then view posts again, the error appears and the page is either unavailable or shows the page with no CSS. Errors in the console show that files failed to load: Failed to load resource: net::ERR_SOCKET_NOT_CONNECTED

This is in a Python 2.7.10 virtualenv on Ubuntu 15.10 running the Flask dev server.

Interestingly, running it in a Python 3.4 virtualenv works without issues. But it would be great to have a fix for Python 2.

Exception happened during processing of request from ('127.0.0.1', 33044)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 655, in __init__
    self.handle()
  File "/home/tom/.virtualenvs/peewee-blog/local/lib/python2.7/site-packages/werkzeug/serving.py", line 216, in handle
    rv = BaseHTTPRequestHandler.handle(self)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/home/tom/.virtualenvs/peewee-blog/local/lib/python2.7/site-packages/werkzeug/serving.py", line 247, in handle_one_request
    self.raw_requestline = self.rfile.readline()
IOError: [Errno 11] Resource temporarily unavailable
coleifer commented 8 years ago

I have no idea, just looks like some kind of problem deep in werkzeug. Not relevant to micawber.

jacquerie commented 8 years ago

I know that I'm doing some necroposting, but this was the only other mention on the internet of the problem we were having, so I felt I had to : )

We were seeing the same exception in our project, despite not using micawber anywhere, and @mihaibivol finally found the culprit: the call to socket.setdefaulttimeout here interferes with the way Flask handles sockets.

Here's a reduced example: https://github.com/jacquerie/isbnlib-flask-error-demo/blob/cf9114853bbc4c52d99098f16c007510d1e0320e/app.py

If you run app.py as it is and access http://localhost:5000 you'll see the error in OP; if you comment those lines out it will be gone.

coleifer commented 8 years ago

Wow, nice find @jacquerie -- I will remove the offending code until I have some more time to investigate. Do you know much about what Flask/werkzeug is doing under-the-hood that isn't compatible with the code in micawber?

mihaibivol commented 8 years ago

@coleifer To our knowledge, when Flask is run with debug it starts two processes (using the fork mechanism). One of them actually serves requests while other listens for changes in files to restart it. The imports are being run in both of the processes and also sockets get inherited. Maybe having a large timeout on sockets on the file change listener process breaks something. We didn't investigate further :)

coleifer commented 8 years ago

121c12c5bab534f4c4605423645ae3ccf4d76831

coleifer commented 8 years ago

Awesome, thanks again @mihaibivol!

keybits commented 8 years ago

Thanks for this :-)