[Django]-Django + WebKit = Broken pipe

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.

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.

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.

👤Evgeny

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.

👤dosht

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!

👤Dave

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

Leave a comment