Django + WebKit = Broken pipe
Asked Answered
R

6

26

I'm running the Django 1.2 development server and I get these Broken Pipe error messages whenever I load a page from it with Chrome or Safari. My co-worker is getting the error as well when he loads a page from his dev server. We don't have these errors when using Opera or Firefox.

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 281, in run self.finish_response()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 321, in finish_response self.write(data)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 417, in write self._write(data)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py", line 300, in write self.flush()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py", line 286, in flush self._sock.sendall(buffer)
error: [Errno 32] Broken pipe

Can anyone help me out? I'm going crazy over this!

Reorder answered 19/5, 2010 at 17:57 Comment(2)
How long does it take for the requested view to run?Archaean
The first time is fast, but after I've gotten the broken pipe error the next page load takes ~10-15 seconds to complete :SReorder
D
22

This is not a Django issue. Your browser is most likely doing something erroneous.

This is common error which happens whenever your browser closes the connection while the dev server is still busy sending data.

Check this Django ticket for more info.

Dahlgren answered 19/5, 2010 at 18:1 Comment(2)
I was just having this problem while use the django development server (1.3 pre-alpha) and this answer is correct in that django is not at fault (browser was Chrome/Safari). I was able to resolve the problem by sending my ajax requests as POST rather than GET. For some reason both browsers were not waiting for the response if the ajax request was made via GET.Gertudegerty
Correct! The answer of @loretoparisi gives an idea of what could cause that behaviour.Mugger
N
13

I just recently ran into this issue with the django v1.1.1 dev server and Chrome 7.0.517.44.

The "fix" that I've discovered is always doing a hard refresh (hold Shift and click the reload button in Chrome) on the page after the initial load, which causes Chrome to ignore it's cache for any resources requested by the refresh.

As such, this leads me to believe it's an issue with Chrome's notorious tendency to cache everything it possibly can; even when it shouldn't. My guess is that Chrome is making a resource request and then immediately dropping the connection for said resource once it realizes it has the resource cached.

This would almost be a bearable workaround, except any AJAX requests will still cause problems.

Niagara answered 11/11, 2010 at 21:7 Comment(0)
J
7

This can be due an error in the javascript function dispatching the ajax call.

For example, the function may be triggered by a click event on a link, and if the default action of link is not prevented, you will get a secondary request right away and the browser will close the previous connection without waiting for the response to finish. I had the same problem when I forgot to add return false to the event handler.

The same symptom can occur if the event handler triggering ajax throws an exception.

Debug carefully the function making the ajax request and the return value of that function.

Jugendstil answered 1/6, 2012 at 9:20 Comment(1)
THANK YOU! I just spent an hour figuring out that I needed that "return False" in my jquery ajax. Its only ever been needed for the POST and as such threw me off this time...Monarchist
C
3

A broken pipe happens when the browser closes the connection with the server. This problem happened with me before on ajax post request associated with <a href="... because I forgot to add e.preventDefault() in the click handler function. So what happened is that the browser send the post request and close the connection and send another get request. So you will see like the post request was canceled by the browser.

Cleo answered 23/5, 2012 at 7:43 Comment(0)
E
2

I had a possibly related problem.

While using Safari and Chrome on Windows, on my local machine on my django runserver, some views were randomly not returning a response to ajax POST requests.

The solution was this:

The data I was passing in to the view via POST was just one key/val pair: "action=remove". Now, I wasn't actually using this data in my view. Once I assigned the data to a var in my view, (i.e. foo = request.POST['action']), the view would return a response to ajax requests every time.

Absolutely crazy!

Employ answered 19/10, 2010 at 17:28 Comment(0)
H
0

In the case that this happens with a JavaScript client, a solution could be the following. You have to add preventDefault and return false at beginning and at the end of your event handler like:

$('#btn_analyze').click(function(e) {
    e.preventDefault()
    $.post('/api/v1/analyzer/',
        data,
        "json").done(function(response) {
        //...
    }).fail(function() {
        Logger.error(" Error ")
    })

    return false
}) // analyze click
Hillie answered 28/5, 2015 at 15:21 Comment(2)
@Reorder right, I had the same problem with a javascript client, that's why. Explained in the answer then!Hillie
Thank you! It's exactly what was causing the problem in Chrome. Firefox would just understand it well. Upvote!Mugger

© 2022 - 2024 — McMap. All rights reserved.