Broken pipe error in Django Nonrel when loading localhost - python

Running Django Nonrel, with Google App Engine 2.6.0 and Python 2.7, I'm getting this exception when trying to load for the first time localhost and localhost/admin (I expect it will happen with any page, though):
Exception happened during processing of request from ('127.0.0.1', 57011)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/google_appengine/google/appengine/tools/dev_appserver.py", line 2438, in __init__
BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "/usr/lib/python2.7/SocketServer.py", line 641, in __init__
self.finish()
File "/usr/lib/python2.7/SocketServer.py", line 694, in finish
self.wfile.flush()
File "/usr/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
Strangely enough, it only appears using Google Chrome. When using Firefox, it doesn't print any exception (or at least, I haven't been able to replicate this problem in Firefox after many tries).
Does anyone know something about this problem?.
Thanks

There have been a few similar reports of race condition issues between Chrome and dev_appserver.py. The usual story is that Chrome opens multiple concurrent connections to the server, but sends a request on the second connection first. Because dev_appserver is single-threaded, the first request blocks, and the server hangs until someone gives up.
Supposedly starting Chrome with --disable-preconnect prevents this condition.

Related

How to keep Werkzeug from crashing after NGINX closes pipe?

I have a Werkzeug server running behind NGINX. When a client disconnects while waiting for the Werkzeug server to respond, NGINX closes the pipe to Werkzeug. When the python program writes the response to Werkzeug, the following exception occurs and Werkzeug crashes:
Traceback (most recent call last):
File "server.py", line 81, in
app.run(host=args.host, port=args.port, debug=False)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 843, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 694, in run_simple
inner()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 659, in inner
srv.serve_forever()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 499, in serve_forever
HTTPServer.serve_forever(self)
File "/usr/lib/python2.7/SocketServer.py", line 238, in serve_forever
self._handle_request_noblock()
File "/usr/lib/python2.7/SocketServer.py", line 297, in _handle_request_noblock
self.handle_error(request, client_address)
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 651, in init
self.finish()
File "/usr/lib/python2.7/SocketServer.py", line 710, in finish
self.wfile.close()
File "/usr/lib/python2.7/socket.py", line 279, in close
self.flush()
File "/usr/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
socket.error: [Errno 32] Broken pipe
Is there some configuration option I'm missing to keep it from crashing? Normally all exceptions are caught and a 500 error returned, with the server remaining alive.
As far as I can guess from the debug trace and without reading the source code, you are probably closing the socket prematurely.
Your server process has received a SIGPIPE writing to a socket. This usually happens when you write to a socket fully closed on the other (client) side. This might be happening when a client program doesn't wait till all the data from the server is received and simply closes a socket (using close function).
In a C program you would normally try setting to ignore SIGPIPE signal or setting a dummy signal handler for it. In this case a simple error will be returned when writing to a closed socket. In your case a python seems to throw an exception that can be handled as a premature disconnect of the client.
How to prevent errno 32 broken pipe?

Broken pipe errno32 LDAP Django

I'm currently trying to use my school's LDAP with a website built with Django. But i'm encountering an error that I'm not able to tackle.
When I am using my school's network the LDAP log in works perfectly on localhost. But when i am using an off-campus network the log-in doesn't work, even the admin login created when i've run manage.py for the first time doesn't work.
The terminal display's the following error each time i try to login :
Traceback (most recent call last):
File "/Users/Me/anaconda/lib/python2.7/wsgiref/handlers.py", line 86, in run
self.finish_response()
File "/Users/Me/anaconda/lib/python2.7/wsgiref/handlers.py", line 128, in finish_response
self.write(data)
File "/Users/Me/anaconda/lib/python2.7/wsgiref/handlers.py", line 212, in write
self.send_headers()
File "/Users/Me/anaconda/lib/python2.7/wsgiref/handlers.py", line 270, in send_headers
self.send_preamble()
File "/Users/Me/anaconda/lib/python2.7/wsgiref/handlers.py", line 194, in send_preamble
'Date: %s\r\n' % format_date_time(time.time())
File "/Users/Me/anaconda/lib/python2.7/socket.py", line 324, in write
self.flush()
File "/Users/Me/anaconda/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
[28/Jan/2014 11:18:43] "POST /admin/ HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 60538)
Traceback (most recent call last):
File "/Users/Me/anaconda/lib/python2.7/SocketServer.py", line 593, in process_request_thread
self.finish_request(request, client_address)
File "/Users/Me/anaconda/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Users/Me/anaconda/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 150, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
File "/Users/Me/anaconda/lib/python2.7/SocketServer.py", line 651, in __init__
self.finish()
File "/Users/Me/anaconda/lib/python2.7/SocketServer.py", line 710, in finish
self.wfile.close()
File "/Users/Me/anaconda/lib/python2.7/socket.py", line 279, in close
self.flush()
File "/Users/Me/anaconda/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------
Thank you very much for your help !
This is an issue with the Django devserver (you are running your website using it, which is not recommended at all for production websites).
Please see this ticket for more details:
According to many sources the 'Broken Pipe' is a normal browser quirk. For example, the browser reads from the socket and then decides that the image it's been reading apparently didn't change. The browser now this (forcefully) closes the connection because it does not need more data. The other end of this socket (the python runserver) now raises a socket exception telling the program that the client 'Broke the socket pipe'.
Short answer is: ignore this error since it's a known error and won't be fixed.
There is also this SO thread talking about this issue.

Handle one HTTP request from python with timeout

I would like to write an application where the main thread start an HTTP server what have to wait for exactly one HTTP request for at most 10 seconds. The application have to be blocked until the request is received (and processed) or the timeout is exceeded.
I tried to use this code:
import BaseHTTPServer
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
s.send_response(200)
s.send_header("Content-type", "text/html")
s.end_headers()
s.wfile.write("<html><head><title>Title</title></head>")
httpd = BaseHTTPServer.HTTPServer(('', 8001), RequestHandler)
httpd.socket.settimeout(10)
httpd.handle_request()
The problem is that when the server receives a request, I get this error message:
Exception happened during processing of request from ('127.0.0.1', 51321)
Traceback (most recent call last):
File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\SocketServer.py", line 639, in __init__
self.handle()
File "C:\Python27\lib\BaseHTTPServer.py", line 343, in handle
self.handle_one_request()
File "C:\Python27\lib\BaseHTTPServer.py", line 313, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "C:\Python27\lib\socket.py", line 476, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 10035] A non-blocking socket operation could not be completed immediately
If I remove the settimeout function, than I don't get this error, but I lost the timeout also. I tried to use the setblocking function too, but it destroy the effect of the settimeout.
How can I reach my goal?
PS.: I am using Python 2.7.2 on a 64-bit Windows 7

Why does requesting an HTML page crash my local Google App Engine server?

Why does requesting an HTML page crash my local Google App Engine server?
This only happens if it's the second or third time I do a request on Internet Explorer 9, and it is not a problem with other browsers.
This is very annoying as I have to restart my server all the time.
The error:
Traceback (most recent call last):
File "C:\Program Files\Python25\lib\SocketServer.py", line 222, in handle_request
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 54978)
self.process_request(request, client_address)
File "C:\Program Files\Python25\lib\SocketServer.py", line 241, in process_request
self.finish_request(request, client_address)
File "C:\Program Files\Python25\lib\SocketServer.py", line 254, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\google_appengine\google\appengine\tools\dev_appserver.py", line 3932, in __init__
BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "C:\Program Files\Python25\lib\SocketServer.py", line 521, in __init__
self.handle()
File "C:\Program Files\Python25\lib\BaseHTTPServer.py", line 316, in handle
self.handle_one_request()
File "C:\Program Files\Python25\lib\BaseHTTPServer.py", line 310, in handle_one_request
method()
File "C:\google_appengine\google\appengine\tools\dev_appserver.py", line 3942, in do_GET
self._HandleRequest()
File "C:\google_appengine\google\appengine\tools\dev_appserver.py", line 4199, in _HandleRequest
raise e
error: (10053, 'Software caused connection abort')
----------------------------------------
I have experienced the same problems. The only thing which helps is to run devappserver with specified IP address of your computer instead of running it on localhost (which is default).
like this:
google_appengine\dev_appserver.py --address=192.168.1.33 myapp
Please can you confirm if it works?
I don't have IE9 but that seems to be like the same problem with Google Chrome:
https://groups.google.com/d/topic/google-appengine-python/0qJlx94aZAE/discussion
https://groups.google.com/forum/#!topic/http-archive-specification/hkdkGknbpdA

error: [Errno 32] Broken pipe when paypal calls back to python django app

Hi I am doing papal integration with my django app.
i am using latest version of django from svn and python 2.6.
However, i found every time when paypal's sandbox accessing my notify url i got 500 [Errno 32] Broken pipe my django stack.
Does anyone have similar experience with this ?
Cheers,
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 281, in run
self.finish_response()
File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 321, in finish_response
self.write(data)
File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 417, in write
self._write(data)
File "/usr/lib/python2.6/socket.py", line 318, in write
self.flush()
File "/usr/lib/python2.6/socket.py", line 297, in flush
self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 104] Connection reset by peer
----------------------------------------
Exception happened during processing of request from ('216.113.191.33', 21736)
Traceback (most recent call last):
File "/usr/lib/python2.6/SocketServer.py", line 283, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 309, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 322, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 562, in __init__
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
File "/usr/lib/python2.6/SocketServer.py", line 618, in __init__
self.finish()
File "/usr/lib/python2.6/SocketServer.py", line 661, in finish
self.wfile.flush()
File "/usr/lib/python2.6/socket.py", line 297, in flush
self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 32] Broken pipe
----------------------------------------
The first error Connection reset by peer show you that the connection have been closed by peer (in your case Pypal) and for the Error Broken pipe this error is raised when a connection is closed suddenly without informing the other peer (in your case your machine).
There are two problems. First, some of the paypal APIs (particularly MassPay) are terribly poor.
The second, and more likely, problem, is that your server is single-threaded and is having trouble properly raising an exception to paypal. I was able to resolve a similar problem by creating an html file with a form (via POST) that mocked a paypal IPN and then looking at the debug result (or better, using a debugger like the one in PyDev). You could do the same thing with curl of course.

Categories