Stuck on SYN_SENT when proxying

239 views
Skip to first unread message

Kevin Dangoor

unread,
Oct 21, 2005, 3:05:20 PM10/21/05
to cherryp...@googlegroups.com
I've been trying to proxy from lighthttpd to the standard CherryPy
server (no SCGI/FastCGI involved) and have been seeing a strange
problem. When I first start it up and CP tries to listen on the
socket, netstat shows the socket in a SYN_SENT state. After some
timeout period, it finally comes up and starts listening. It works,
but it's annoying to have a wait a minute whenever you restart the
server.

Has anyone else seen this? Is there an easy solution?

Thanks!
Kevin

--
Kevin Dangoor
Author of the Zesty News RSS newsreader

email: k...@blazingthings.com
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com

Robert Brewer

unread,
Oct 21, 2005, 4:55:06 PM10/21/05
to cherryp...@googlegroups.com
Kevin Dangoor wrote:
> I've been trying to proxy from lighthttpd to the standard CherryPy
> server (no SCGI/FastCGI involved) and have been seeing a strange
> problem. When I first start it up and CP tries to listen on the
> socket, netstat shows the socket in a SYN_SENT state. After some
> timeout period, it finally comes up and starts listening. It works,
> but it's annoying to have a wait a minute whenever you restart the
> server.
>
> Has anyone else seen this? Is there an easy solution?

My guess is that you're seeing cherrypy._cpserver.Server check that its
own port is ready to receive requests (which it does via
socket.connect(); socket.close()). See wait_for_free_port and
wait_for_occupied_port in that module. If you're experiencing timeouts
of more than a second, then 1) there's something wrong with the HTTP
server, and 2) CP therefore won't let you receive requests, by design.


Robert Brewer
System Architect
Amor Ministries
fuma...@amor.org

Kevin Dangoor

unread,
Oct 25, 2005, 12:23:10 PM10/25/05
to cherryp...@googlegroups.com
Hi Robert,
I've taken a look to see exactly where it's stopping.

In check_port, it creates the socket and then it waits on the
s.connect line for a minute. Apparently, after that minute it gets a
socket.error and then proceeds to bind properly.

This is a FreeBSD machine (which I have little experience with). On my
Mac, I get an immediate "connection refused". On this FreeBSD machine,
it hangs around in SYN_SENT for a minute before complaining. That
seems a tad annoying.

Kevin Dangoor

unread,
Oct 25, 2005, 1:09:44 PM10/25/05
to cherryp...@googlegroups.com
On 10/25/05, Kevin Dangoor <dan...@gmail.com> wrote:
> This is a FreeBSD machine (which I have little experience with). On my
> Mac, I get an immediate "connection refused". On this FreeBSD machine,
> it hangs around in SYN_SENT for a minute before complaining. That
> seems a tad annoying.

A bit of Googling has turned up a page with a FAQ (for sendmail, I
think) that basically said "some systems' TCP implementations time out
rather than refusing the connection". I seem to be working with one of
those.

What do you think of adding a 1 second time out to that socket?
Particularly for localhost connections, it should take far less than a
second to just make a TCP connection.

Kevin

Robert Brewer

unread,
Nov 6, 2005, 11:40:47 PM11/6/05
to cherryp...@googlegroups.com
I don't have a FreeBSD machine handy. :/ Can you test the following and see if it resolves your issue? Change check_port to read:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1.0)
s.connect((host, int(port)))
s.close()
winmail.dat

Kevin Dangoor

unread,
Nov 7, 2005, 12:01:59 AM11/7/05
to cherryp...@googlegroups.com
On 11/6/05, Robert Brewer <fuma...@amor.org> wrote:
> I don't have a FreeBSD machine handy. :/ Can you test the following and see if it resolves your issue? Change check_port to read:
>
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.settimeout(1.0)
> s.connect((host, int(port)))
> s.close()

TurboGears currently has a monkeypatch that does that very thing, so
yes that works fine on the machine in question. Also, it turned out to
not be a FreeBSD-ism, but rather a firewall feature. But, this still
seems to be a good fix for the problem.

Kevin
Reply all
Reply to author
Forward
0 new messages