Django

Code

Ticket #4444 (closed: wontfix)

Opened 1 year ago

Last modified 5 months ago

broken pipe issue

Reported by: vanderkerkoff Assigned to: nobody
Milestone: Component: django-admin.py runserver
Version: SVN Keywords: broken pipe 32
Cc: sandro@e-den.it, mpjung@terreon.de Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by mtredinnick)

Hello everyone

I've had a good day looking into this and can't work out what the f*ck is going on.

I've updated my django_src as of today, 31/05/07.

My sites are all running fine, but if I'm using Firefox 2.0.0.4 I'm getting the error below appear in my terminal. It doesn't happen with Safari, but it does screw AB up, only one request gets returned.

Can anyone shed some light on this issue, I'd be really grateful.

Traceback (most recent call last):
  File "/usr/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 273, in run
    self.finish_response()
  File "/usr/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 312, in finish_response
    self.write(data)
  File "/usr/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 389, in write
    self.send_headers()
  File "/usr/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 441, in send_headers
    self.send_preamble()
  File "/usr/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 372, in send_preamble
    self._write('Date: %s\r\n' % time.asctime(time.gmtime(time.time())))
  File "/usr/local/lib/python2.5/socket.py", line 261, in write
    self.flush()
  File "/usr/local/lib/python2.5/socket.py", line 248, in flush
    self._sock.sendall(buffer)
error: (32, 'Broken pipe')

Attachments

django_core_servers_basehttp-fix-broken-pipe.diff (1.3 kB) - added by trbs on 05/31/08 13:47:01.
django.core.servers.basehttp saner broken pipe message
django_core_servers_basehttp-fix-broken-pipe.2.diff (0.9 kB) - added by trbs on 05/31/08 13:53:50.

Change History

06/01/07 02:40:04 changed by mtredinnick

  • needs_better_patch changed.
  • description changed.
  • needs_tests changed.
  • needs_docs changed.

What is the minimum that has to be done to cause the problem? What are you doing in Firefox to cause the error to occur? There is nothing repeatable in this bug report, so it's a bit hard to proceed further.

06/01/07 04:03:23 changed by anonymous

  • status changed from new to closed.
  • resolution set to invalid.

I confused myself yesterday by assuming that the development server runserver would behave in the same manner as lighttpd and fcgi when you throw AB at it, dumass as I am. Runserver can't handle AB tests, and if you think about it for one second you will realise this. I just assumed and then went to bad places from there.

I tracked ths issue down and it's nothing at all to do with Django

One of our designers had loaded webdesign into the tempalte that was being called in.

This webdesign randomises lorem ipsum output so that the desginers can imitate different types of text output, that was giving AB a real headache. Removed it and django runs like the wind again.

I sincerely apologise for posting this up here, it's the wrong place but I didn't know it at the time.

Hopefully it might help someone else at some point in time, eh Ed ;-)

06/01/07 07:16:51 changed by anonymous

For searching purposes, AB is referring to Apache Server Benchmarking Tool. "AB" is too short to search for.

06/05/07 18:05:31 changed by anonymous

  • status changed from closed to reopened.
  • resolution deleted.

I'm also getting the same of similar error from runserver.

Traceback (most recent call last):

File "/usr/local/lib/python2.4/site-packages/django/core/servers/basehttp.py", line 273, in run

self.finish_response()

File "/usr/local/lib/python2.4/site-packages/django/core/servers/basehttp.py", line 312, in finish_response

self.write(data)

File "/usr/local/lib/python2.4/site-packages/django/core/servers/basehttp.py", line 396, in write

self._write(data)

File "/usr/local/lib/python2.4/socket.py", line 256, in write

self.flush()

File "/usr/local/lib/python2.4/socket.py", line 243, in flush

self._sock.sendall(buffer)

error: (32, 'Broken pipe')

It seems to work fine on my development box, but when I try to test django on a production server (using the servers IP instead of localhost - manage.py runserver 192.168.***.*** 8000). I've also noticed that {{ request.user.first_name }} doesn't work in my templates when on the production server - but it does work on my dev box...

06/05/07 18:07:43 changed by anonymous

Also - Firefox and IE both pull the error. It doesn't seem to be limited to Firefox in my case. The only non-standard library I'm using is Sphene Community - http://sct.sphene.net/wiki/show/Start/

06/26/07 12:04:11 changed by berto

I'm seeing this problem on my machine with Firefox 2.0.0.4. I can confirm it does not happen with Safari.

I tried this on a bare install, with the following INSTALLED_APPS:

    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',

There are no additional middleware or template loaders either.

I can get the error by simply accessing the admin site.

06/27/07 05:54:47 changed by sandro@e-den.it

  • version changed from 0.96 to SVN.

I get this consitently if I add ThreadLocals? middleware defined here:

http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser

at this point browsing admin site outputs the error in the developement console. Appearently there is no other problem. Sometimes I get the error only on the second hit of the page

06/27/07 06:05:23 changed by anonymous

  • cc set to sandro@e-den.it.

06/27/07 21:21:14 changed by anonymous

I can confirm this does not happen the first time a page is accessed using the development server (e.g. when you make a change to the code and the server reloads). The exception occurs the second and any subsequent page request.

07/21/07 11:22:28 changed by anonymous

  • cc changed from sandro@e-den.it to sandro@e-den.it, mpjung@terreon.de.

07/24/07 19:43:56 changed by eatmywake AT gmail DOT com

Hi,
I was getting this error too (with Mozilla Firefox v2.0.0.5 and Mozilla Seamonkey v1.1.3 on Fedora7 served by Django v0.96, dev server), however what I found interesting was that I was able to replicate & eliminate (or decrease the frequency of the error, at least) in my app! I'll explain a little what I was up to.

I'm building a chat room app with Django and its AJAXed using YUI toolkit. Part of the app is a continuous loop, which polls the server for updates. This is simplifing things a bit, but the app has, lets say, a poll interval and a timeout period setting, so that if a request doesn't return from the server within the timeout period, the request is aborted.

What I found (and it kinda makes sense, with hindsight...) was that by making the timeout period much less than the poll interval, say half, the frequency of the error was much reduced. At the moment I'm not getting any errors. I think I may have been DoS-ing my own machine by sending too many requests, before the previous requests had completed!!
I don't know if this will help the ticket resolution, but the same error had me head scratching for a while.
Tom (Mayo, Ireland.)

Below is the exact error copied from my terminal;

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 273, in run
    self.finish_response()
  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 312, in finish_response
    self.write(data)
  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 391, in write
    self.send_headers()
  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 443, in send_headers
    self.send_preamble()
  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 373, in send_preamble
    'Date: %s\r\n' % time.asctime(time.gmtime(time.time()))
  File "/usr/lib/python2.5/socket.py", line 261, in write
    self.flush()
  File "/usr/lib/python2.5/socket.py", line 248, in flush
    self._sock.sendall(buffer)
error: (32, 'Broken pipe')

08/19/07 06:37:56 changed by anonymous

I am getting exactly this same error. However, in my case the socket connection is coming from a JavaScript? I'm running inside After Effects (the script is spawned by my Django app via AppleScript? and After Effects defines a Socket object for its scripts). So, I don't think it's a browser issue. Same deal as above, the first time the view is called (in my case it's really just a function and not technically a "view" since it never sends an HttpResponse to the browser), the socket works perfectly; data is transmitted and received, and the sockets appear to be closed properly. The second time I hit this view, however, I get the same broken pipe error and trace in the Terminal as listed above and no socket is opened.

Here is my view code:

{{{def test_socket(request):

print 'TESTING SOCKET'

conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if conn is None:

print 'Connection is invalid, bailing.' return None

conn.bind((, 7021)) print 'SERVER: waiting for connection.' conn.listen(5) print 'SERVER: listening.'

try:

try:

newSocket, address = conn.accept() print 'SERVER: connected from address', address

while True:

rawData = newSocket.recv(8192) print 'SERVER: received data: "%s"' % rawData

if rawData is not None:

# newSocket.shutdown(1) # We got the data, get out of the loop break

finally:

if newSocket is not None:

newSocket.sendall('DONE') newSocket.close() print 'SERVER: data receive socket closed.'

finally:

if conn is not None:

conn.close() print 'SERVER: main socket closed.'

print 'SOCKET TEST COMPLETED'

return None}}}

08/19/07 06:40:46 changed by anonymous

Sorry, I guess to use WikiFormatting, the braces need to be on their own line, trying again with code sample...

def test_socket(request):
	print 'TESTING SOCKET'

	conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	if conn is None:
		print 'Connection is invalid, bailing.'
		return None
		
	conn.bind(('', 7021))
	print 'SERVER: waiting for connection.'
	conn.listen(5)
	print 'SERVER: listening.'

	try:
		try:
			newSocket, address = conn.accept()
			print 'SERVER: connected from address', address
			
			while True:
				rawData = newSocket.recv(8192)
				print 'SERVER: received data: "%s"' % rawData

				if rawData is not None:
					# newSocket.shutdown(1)
					# We got the data, get out of the loop
					break
		finally:
			if newSocket is not None:
				newSocket.sendall('DONE')
				newSocket.close()
				print 'SERVER: data receive socket closed.' 
	finally:
		if conn is not None:
			conn.close()
			print 'SERVER: main socket closed.'

	print 'SOCKET TEST COMPLETED'
	
	return None

09/14/07 13:01:28 changed by PhiR

  • status changed from reopened to closed.
  • resolution set to wontfix.

This is common error which happens whenever your browser closes the connection while the dev server is still busy sending data. The best we could is to have a more explicit error message.

05/31/08 13:47:01 changed by trbs

  • attachment django_core_servers_basehttp-fix-broken-pipe.diff added.

django.core.servers.basehttp saner broken pipe message

05/31/08 13:53:39 changed by trbs

added a patch which results in a saner default message for the 'broken pipe' issue that happens whenever a browsers closes the connection early.

i found that this mostly/exclusively with '/favicon.ico' on my test project.

the patch changes the output from a lengthy traceback message to:

[31/May/2008 20:47:21] "GET /favicon.ico HTTP/1.1" 200 6335 Broken pipe

Since /favicon.ico is normally ignored by the logs messages it might make good sense to ignore the 'broken pipe' from this path too. This is where the second patch comes in :) It's much cleaner as it uses the normal log_request routine. (and thus ignores the favicon path)

05/31/08 13:53:50 changed by trbs

  • attachment django_core_servers_basehttp-fix-broken-pipe.2.diff added.

05/31/08 14:09:31 changed by trbs

  • has_patch set to 1.
  • component changed from Core framework to django-admin.py runserver.

06/15/08 23:48:30 changed by anonymous

I am still having problems with this broken pipe issue. And I am using the newest django distribution 0.96.2. When I try to access my development server with http://192.168.0.3:8000/myurl/ I get the error displayed. And the patches didn't solve anything...

06/15/08 23:52:37 changed by anonymous

And I have installed both patches and if I fast click many times to reload my page I get the following error message:

Traceback (most recent call last):

File "/usr/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 273, in run

self.finish_response()

File "/usr/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 312, in finish_response

self.write(data)

File "/usr/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 396, in write

self._write(data)

File "/usr/local/lib/python2.5/socket.py", line 262, in write

self.flush()

File "/usr/local/lib/python2.5/socket.py", line 249, in flush

self._sock.sendall(buffer)

error: (104, 'Connection reset by peer')

06/16/08 08:08:31 changed by trbs

Dear anonymous,

There is nothing to 'fix' here in your application, your just experiencing a browser issue/quirk.

This is exactly the reason i voted for changing these kinds of tracebacks to less scary looking errors and hiding the traceback behind --traceback. (this's what the switch it's for no ? :)

The reason for this patch is not to 'fix' the broken pipe issue. As it's not really an issue. But there seems to be a lack of clear consensus on how serious this is.

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'.

If this is really only a non-issue, aka browsers do this often and it's not serious, then i suggested that we at least change this to a slightly less scary looking error. The idea here is to turn an exception (which is programming lingo) into an user error.

Hopefully this explains the issue a bit better for people hitting it.

06/16/08 08:42:08 changed by ramiro

One thing the multiple reporters don't make clear is if the development web server keeps running or if this is a non fatal error.

Maybe a FAQ entry could be added with a blurb similar to trbs explanation above or to how CherryPy people describe the issue: http://www.cherrypy.org/wiki/CherryPyBrokenPipe

06/16/08 09:01:07 changed by trbs

That might be a good idea for both sides on this discussion ? :)

If we create a decent wiki page for this and put the wiki page in the exception raised by Django then it would be clear to people what the error is about.


Add/Change #4444 (broken pipe issue)




Change Properties
Action