I've an apple iphone application that's using web services implemented in Python, using Django and Piston, running with an apache server through WSGI.

Sometimes the application shuts its link with the server before a phone call is completed. If this performs this it leads to a:

[Tue Sep 06 11:29:46 2011] [error] [client] mod_wsgi (pid=820): Exception occurred processing WSGI script 'myscript.wsgi'.
[Tue Sep 06 11:29:46 2011] [error] [client] IOError: failed to write data

to look during my server's error logs.

I'm able to "fix" the issue in the application by not clearly closing the bond, but simply departing it to complete installing and disregarding the end result. However, I would like fix this around the server-side if at all possible. How do i get it done?

[disclaimer: this can be a "why it cannot easily be done" explanation, not really a solution]

As @Slott stated, this really is certainly the technically correct behavior when stream.close or stream.write is known as on the closed socket. However, I realize the motivation for that question... poor a wsgi application, clients terminating the bond following a full or partial read isn't an "exceptional" behavior, it takes place constantly. For this to become left unhandled leaves the sense it had been unpredicted / the code was not really prepared with this, much more fact it's expected, and should not be worth note. So it would be nice to repair.

The issue is the fact that you'd need to try to distinguish cases different cases...

  • Situations like "client read 'Status: 304' and closed connection" or "client read all bytes and closed connection if this had asked for connection ought to be used again" are the ones where it might be appropriate not to problem any kind of logging besides a log.debug() call.

  • But situtations like "client stopped reading through in the center of file because connection died when Web service provider router were built with a stroke" are worth a mistake being drenched. Something did not effectively complete, and then any transactional condition your server application builtup ought to be folded back. By which situation IOError propagating upwards may be the right factor to complete.

Such errors are just silenceable if at each place they may be elevated, the code is modified to tell apart individuals two cases. For now, the wsgi authors appear to possess erred along the side of caution. So there is not a fast fix with this which i are conscious of.

(Also, I ought to note this is not django-specific, I personally use paste+pylons and also have the same factor happen)

Check this out: http://code.google.com/p/modwsgi/issues/detail?id=29

If processing iterable, then message drenched a debug level with no Python exception used. Thus to determine client closed connection problems when iterable used, then need LogLevel to become debug.

Apparently, you should tweak your Django reaction to be an iterable rather than a string.