views:

21

answers:

2

Hi there,

I'm serving requests from several XMLRPC clients over WAN. The thing works great for, let's say, a period of one day (sometimes two), then freezes in socket.py:

data = self._sock.recv(self._rbufsize)

_sock.timeout is -1, _sock.gettimeout is None

There is nothing special I do in the main thread (just receiving XMLRPC calls), there are another two threads talking to DB. Both these threads work fine and survive this block (did a check with WinPdb). Clients are sending requests not being longer than 1KB, and there isn't any special content: just nice and clean strings in dictionary. Between two blockings I serve tens of thousands requests without problems. Firewall is off, no strange software on the same machine, etc...

I use Windows XP and Python 2.6.4. I've checked differences between 2.6.4. and 2.6.5, and didn't find anything important (or am I mistaking?). 2.7 version is not an option as I would miss binaries for MySqlDB.

The only thing that happens from time to time caused by the clients that have poor internet connection is that sockets break. This is happening, every 5-10 minutes (there are just five clients accessing server every 2 seconds).

I've spent great deal of time on this issue, now I'm beginning to lose any ideas what to do. Any hint or thought would be highly appreciated.

A: 

What exactly is happening in your OS's TCP/IP stack (possibly in the python layers on top, but that's less likely) to cause this is a mystery. As a practical workaround, I'd set a timeout longer than the delays you expect between requests (10 seconds should be plenty if you expect a request every 2 seconds) and if one occurs, close and reopen. (Calibrate the delay needed to work around freezes without interrupting normal traffic by trial and error). Unpleasant to hack a fix w/o understanding the problem, I know, but being pragmatical about such things is a necessary survival trait in the world of writing, deploying and operating actual server systems. Be sure to comment the workaround accurately for future maintainers!

Alex Martelli
Hi Alex, just to report you back shortly that it all went fine. Now after 5 days without any problem I dare to say that. The catch was really in a fixed timeout without leaving SimpleXmlRPCServer on it's default timeout (None). You completely resolved my problem by this suggestion.However, two days ago I caught urlib2 suffering from the almost the same problem. It froze in sockets.py as well (other socket.recv call, just a few lines away from the previous one).
Igor Kramaric
A: 

Hi Alex, thanks so much for the fast response. Right after I've receive it I augmented the timeout to 10 seconds. Now it is all running without problems, but of course I would need to wait another day or two to have sort of confirmation, but only after 5 days I'll be sure and will come back with the results. I see now that 140K request went well already, having so hard experience on this one I would wait at least another 200K.

What you were proposing about auto adaptation of timeouts (without putting the system down) sounds also reasonable. Would the right way to go be in creating a small class (e.g. AutoTimeoutCalibrator) and embedding it directly into serial.py?

Yes - being pragmatical is the only way without loosing another 10 days trying to figure out the real reason behind.

Thanks again, I'll be back with the results. (sorry, but for some reason I was not able to post it as a reply to your post)

Igor Kramaric