Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 199e79ee8922c7ebe0ba4d0d1063be175384f717
Ticket: 1437595fffffffffffffffffffffffffffffffff
WinSock cores/hangs on thread or app exit
User & Date: andreas_kupries on 2006-03-01 05:16:02
Changes

  1. icomment:
    Logged In: YES 
    user_id=75003
    
    
    > OK. Easy.  But you will have to follow me...
    
    I will try.
     
    > If you open a socket, don't close it and exit the thread
    > (or the application,  this will eventually come to
    > 
    >   Tcl_FinalizeThread()
    > 
    > The Tcl_FinalizeThread will pull thread-exit handlers
    > one by one. One of them will be the handler to tear down
    > the socket subsystem.
    
    > This thread-exit handler will tear-down the socket thread and
    > all the sync primitieves for the synchronization. After that 
    > no calls into this subsystem should be performed.
    
    Ah, now I see what problem I had before. I was looking at
    the TclpFinalizesockets for the Mac :( D'oh.
    
    > But....
    > After that, the TclFinalizeIOSubsystem() is called.
    > The TclFinalizeIOSubsystem walks the list of opened channels,
    > founds one still opened and tries to close it (line 254 in 
    > generic/tclIO.c).
    > The Tcl_Close will invoke CloseChannel and this will call
    Tcl_CutChannel.
    > The Tcl_CutChannel will, as the last step of operation, call
    > ThreadActionProc with  TCL_CHANNEL_THREAD_REMOVE.
    > Understand? Now, the ThreadActionProc will result in 
    > TcpThreadActionprroc (line 2689 win/tclWinChan.c) and will
    start 
    > using tsdPtr->socketListLock, will attemt to SendMessage to 
    > window owned by the SocketThread which already is exited 
    > and so on and so on... 
    
    Ok, yes I see the problem with that. So the new ThreadAction
    stuff I did caused this, due to not fully understood
    finalize ordering. My apologies. Although ... No, we had no
    thread actions before, causing crashes when the socket moved
    around between threads. My integration fixes this, and
    opened the problem with the finalize ordering :( Thanks for
    finding and fixing this.
    
    
    > Is this now little bit more clear?
    
    Yep.
     
    > Concerning lazy init/teardown of socket subsystem, the
    answer is: yes.
    > If this is in place, then this will be better and more
    logical. The first
    > channel/socket inits, the last closing tears down the
    subsystem.
    > This is how I'd do the thing If I had designed it.
    
    Note: ThreadActions are a very new thing, they were not
    available when the driver was written initially.
    
    > But I was not so I
    > had to at least rectify the obviously broken current
    implementation.
    
    I guess we can try to rewrite the driver to use of the
    thread actions in this way, now that the problem is fixed.
    
    Note: Do you have test cases which demonstrate the crash
    with the old implementation ? That would be good to have to
    prevent any future implementation from running into the same
    trap.
    
    
    
  2. login: "andreas_kupries"
  3. mimetype: "text/plain"
  4. username: "andreas_kupries"