/ Zope / Apsis / Pound Mailing List / Archive / 2004 / 2004-08 / "Connection refused" under high load

[ << ] [ >> ]

[ errors / "Alexander Meis" ... ] [ RE: Pound and ASP on IIS / "John D" ... ]

"Connection refused" under high load
Dmitry Dvoinikov <dmitry(at)targeted.org>
2004-08-23 14:47:10 [ FULL ]
I'm having yet another problem with Pound 1.7 under FreeBSD 4.10,
this time it's about thread-safetiness of socket operation. The
problem is easily repeatable.

The problem is as follows - under high load there is a chance
that two threads while simultaneously connecting to the backend
get bound to the same local port (!) and therefore only one
connect() succeeds, the other returns error.

I have tried inserting a call to bind() with zero local port
just before connect() in http.c:725, hoping manual binding will
work correctly. Didn't help. Next time I tried introducing a
dedicated pthread mutex and surrounding that bind() call with
lock/unlock pair. Didn't help either.

Here is a dump generated by the modified Pound:

Aug 23 17:01:46  pound: bound to 17486
Aug 23 17:01:46  pound: bound to 9338
Aug 23 17:01:46  pound: bound to 56138
Aug 23 17:01:46  pound: bound to 2827
Aug 23 17:01:46  pound: bound to 10020
***> Aug 23 17:01:46  pound: bound to 37963
Aug 23 17:01:46  pound: bound to 36905
Aug 23 17:01:46  pound: bound to 29065
Aug 23 17:01:46  pound: bound to 42025
Aug 23 17:01:46  pound: bound to 65385
Aug 23 17:01:46  pound: bound to 20159
***> Aug 23 17:01:46  pound: bound to 37963
Aug 23 17:01:46  pound: backend 127.0.0.1:80 connect: Connection refused

And such pattern repeats for every "Connection refused" error.

Pound is built with -D_REENTRANT -D_THREAD_SAFE as I assume
it should be and is linked to the libc_r.so.4 which is the
right thing as well.

I have also tried to pkg_add pound-1.7 from ports, assuming
it has relevant patches applied, but it didnt't help - I'm
seeing the same behaviour - "Connection refused" (although
as there is no source I'm not 100% sure the problem is the
same).

Other than killing the socket and retrying to connect, is
there any easy way to fix this ?

Sincerely,
Dmitry Dvoinikov
http://www.targeted.org/

Re: "Connection refused" under high load
Robert Segall <roseg(at)apsis.ch>
2004-08-23 15:28:36 [ FULL ]
On Monday 23 August 2004 14.47, Dmitry Dvoinikov wrote:[...]

I can't see why you would want to bind() your socket to anything - this is a 
client connection to a back-end.

If indeed two connect() calls can result in the same client-side address being 
assigned then the FreeBSD developers should be happy to have a bug pointed 
out to them. I suspect however that such a serious bug would been found much 
earlier.

Normally a connect() fails because of resource starvation (out of file 
descriptors or similar), or, more often, because of a time-out (the server is 
too busy to reply fast enough, your network is overloaded, etc). I suggest 
you check these possibilities first.

I repeat my original recommendation to move to -current, which supports (among 
others) full control of async time-outs.[...]

MailBoxer