Threaded socket hang in 1.3.20

Jason Tishler
Thu Feb 20 17:47:00 GMT 2003


On Thu, Feb 20, 2003 at 03:15:39PM +0100, Corinna Vinschen wrote:
> I looked into this problem

Thanks for your help -- it is much appreciated.

> and it turns out to be a non-socket specific problem but instead a
> deadlock problem in cygheap:
> [snip]
>   cygheap_fdnew (int seed_fd = -1, bool lockit = true)
>     {
>       if (lockit)
> 	SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "cygheap_fdnew");

I came to the above conclusion yesterday, but did not have a chance to
report back to the list.

> [snip]
> I've cleaned that up a bit and commited the changes.

Thanks!  The two Python regression tests no longer hang with the latest

> Now back to the test case.  With these changes the socket() call doesn't
> hang but now connect() is in trouble.  It hangs for a while until it
> returns with error 116, Connection timeout.

I just tried the test case again and it still fails with 111.  FWIW, I
happened to notice that the test case fails with 116 on 1.3.17 (on my
home PC).

YA FWIW, see attached.  I know that you do read Python, but this code
shows that connect() works with threads in at least one situation.
Maybe there is a bug in my test case?  Note that I'm only lightly versed
in sockets -- just enough to be dangerous.

> I must admit, that I didn't find the cause so far.  Help in debugging
> this is appreciated.

I will try to poke around some more.


PGP/GPG Key: or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
-------------- next part --------------
# test asynchat -- requires threading

import thread # If this fails, we can't test this module
import asyncore, asynchat, socket, threading, time

HOST = ""
PORT = 54321

class echo_server(threading.Thread):

    def run(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind((HOST, PORT))
        conn, client = sock.accept()
        buffer = ""
        while "\n" not in buffer:
            data = conn.recv(10)
            if not data:
            buffer = buffer + data
        while buffer:
            n = conn.send(buffer)
            buffer = buffer[n:]

class echo_client(asynchat.async_chat):

    def __init__(self):
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connect((HOST, PORT))
        self.buffer = ""

    def handle_connect(self):
        print "Connected"

    def collect_incoming_data(self, data):
        self.buffer = self.buffer + data

    def found_terminator(self):
        print "Received:", `self.buffer`
        self.buffer = ""

def main():
    s = echo_server()
    time.sleep(1) # Give server time to initialize
    c = echo_client()
    c.push("hello ")


More information about the Cygwin-developers mailing list