Skip to content
Tcl Source Code History Of Ticket 1028264
Login

History Of Ticket 1028264

Artifacts Associated With Ticket 1028264

  1. Ticket change [0ed8682114] (rid 94690) by dgp on 2004-09-14 23:30:21:

    1. assignee initialized to: "andreas_kupries"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      
      Seeing very troubling
      socket failures only on Windows.
      (Testing with ActiveTcl 8.4.7.0)
      
      First here's a script that implements
      an echo server on port 1111, it
      takes a command line argument
      which adds delays in milliseconds
      to simulate the server having to
      attend to other tasks between
      servicing the socket when idle.
      
    4. foundin initialized to: "obsolete: 8.4.7"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "dgp"
    9. subsystem initialized to: "27. Channel Types"
    10. title initialized to: "Win socket: failed write prevents read"
    11. type initialized to: "Bug"
  2. Add attachment "server.tcl" [3aaab26c2a] (rid 112597) by dgp on 2004-09-15 06:30:21.

  3. Ticket change [d76533d33b] (rid 123978) by dgp on 2004-09-15 06:30:21:

    1. icomment:
      
      
      File Added - 101511: server.tcl
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  4. Ticket change [480e05b2f5] (rid 99819) by dgp on 2004-09-15 07:05:40:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      And here is a script that implements
      a client of that server.  It connects
      to the server and sends and receives
      messages from it.  It also takes a command
      line argument to add delays between
      messages it sends, representing time
      the client program is busy tending to
      other tasks.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  5. Add attachment "client.tcl" [381907d09f] (rid 112148) by dgp on 2004-09-15 07:05:40.

  6. Ticket change [2617fae676] (rid 88281) by dgp on 2004-09-15 07:05:41:

    1. icomment:
      
      
      File Added - 101513: client.tcl
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  7. Ticket change [f9e283b665] (rid 91771) by dgp on 2004-09-15 07:08:31:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      Now let the server have delays longer
      than the client, so that a queue of
      messages can be waiting to be
      read by the server.  Say a value 
      of 1000 for server.tcl and 200 for client.tcl.
      Then I see what I like on Solaris.
      From client.tcl:
      
      $ tclsh client.tcl 200
      Writing message  1
      Writing message  2
      Writing message  3
      Writing message  4
      Writing message  5
      Writing message  6
       Reply from server: Message  1 received: This is message  1
      Writing message  7
      Writing message  8
      Writing message  9
      Writing message 10
      Socket closed
      
      From server.tcl:
      $ tclsh server.tcl 1000
      [ 1]==>This is message  1
       Response: Message  1 received: This is message  1
      [ 2]==>This is message  2
       Response: Message  2 received: This is message  2
      [ 3]==>This is message  3
       Response: Message  3 received: This is message  3
      [ 4]==>This is message  4
       Response: Message  4 received: This is message  4
      OUTPUT ERROR on socket sock4: error writing "sock4": broken pipe
      [ 5]==>This is message  5
      [ 6]==>This is message  6
      [ 7]==>This is message  7
      [ 8]==>This is message  8
      [ 9]==>This is message  9
      [10]==>This is message 10
      INPUT EOF detected on socket sock4; closing socket.
      
      Note that server.tcl was able to read
      all 10 messages from the client.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. title changed to: "socket: failed write prevents read"
    5. username: "dgp"
  8. Ticket change [0ec655822f] (rid 94674) by dgp on 2004-09-15 07:13:48:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      Reliably on Windows, and sometimes
      on Linux/Alpha, I see this undesirable
      result from server.tcl instead:
      
      $ tclsh server.tcl 1000
      [ 1]==>This is message  1
       Response: Message  1 received: This is message  1
      [ 2]==>This is message  2
       Response: Message  2 received: This is message  2
      [ 3]==>This is message  3
       Response: Message  3 received: This is message  3
      OUTPUT ERROR on socket sock812: error writing "sock812":
      connection reset by peer
      [ 4]==>This is message  4
      [ 5]==>This is message  5
      INPUT EOF detected on socket sock812; closing socket.
      
      Note most importantly that
      messages 6 through 10 are lost!
      Data loss is bad, mm-kay?
      
      Note also the different error message.
      
      Anything that can be done to make
      socket communications more reliable?
      
      Also, is this a new problem?  I don't
      recall noticing it before.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  9. Ticket change [1670238d0d] (rid 124718) by dgp on 2004-09-15 07:31:29:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      
      On Linux/Alpha I tested several
      older Tcl versions and saw the
      same problem.  Not new, just
      newly noticed.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  10. Ticket change [60a04f448a] (rid 116031) by andreas_kupries on 2005-10-06 06:00:07:

    1. icomment:
      Logged In: YES 
      user_id=75003
      
      Still present in the 8.4 head ? 8.5 as well ?
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  11. Ticket change [8f0af79144] (rid 120217) by dgp on 2006-03-10 13:42:56:

    1. assignee changed to: "dgp"
    2. icomment:
      Logged In: YES 
      user_id=80530
      
      
      time to check this again.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. priority changed to: "9 Immediate"
    6. username: "dgp"
  12. Ticket change [1007e69440] (rid 94894) by dgp on 2006-03-24 02:16:49:

    1. assignee changed to: "andreas_kupries"
    2. icomment:
      Logged In: YES 
      user_id=80530
      
      still see same behavior
      in 8.4.13 -- reliable
      data transport on Solaris.
      Data loss on (ancient) Linux/Alpha.
      Did not retest on Windows.
      
      ditto for 8.5a4.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. username: "dgp"
  13. Ticket change [4834d47a05] (rid 99843) by nobody on 2007-05-16 03:33:01:

    1. icomment:
      Logged In: NO 
      
      still buggy getting ready to
      release 8.4.15.
      
      Can't we do anything about this?
      
      
      
      
    2. login: "[email protected]"
    3. mimetype: "text/plain"
    4. username: "[email protected]"
  14. Ticket change [e599565165] (rid 104146) by dgp on 2007-12-07 02:33:51:

    1. icomment:
      Logged In: YES 
      user_id=80530
      Originator: YES
      
      
      won't block 8.5.0 for this.
      It really sucks this is still
      broken, but it's not any more
      broken than 8.4.* have been.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. priority changed to: "8"
    5. username: "dgp"
  15. Ticket change [fce6fa275e] (rid 108313) by ferrieux on 2008-11-09 04:15:25:

    1. icomment:
      Attaching much simpler test case: all synchronous, no fileevents.
      Repro on Win32.
      Start server:  tclsh srv.tcl INITIAL-PAUSE-IN-MILLISECONDS
      Start client:  tclsh cli.tcl
      Principle: client connects, sends 1 lines quickly, exits (closes).
      Server accepts connection, pauses the given number of ms, gets 1 line, then does a puts yielding a ECONNRESET, then reads the tail and displays it.
      
      Result:
       - With initial pause is large enough (100ms is okay), the tail is reliably empty
       - With no initial pause, the tail varies from 0 to 7 lines at random
      
      Notice that both are pathological. I like the first because it is easier to debug (no race condition): looks like the input is read and buffered inside Tcl's generic buffered input layer, but somehow discarded because of the ECONNRESET.
      
      Investigation going on ;-)
       
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  16. Ticket change [1c6849ba4d] (rid 90600) by ferrieux on 2008-11-09 04:16:08:

    1. icomment:
      
      
      File Added - 300679: cli.tcl
      
      File Added: cli.tcl
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  17. Add attachment "cli.tcl" [d9442764fe] (rid 107581) by ferrieux on 2008-11-09 04:16:08.

  18. Add attachment "srv.tcl" [26fce34e24] (rid 88440) by ferrieux on 2008-11-09 04:17:58.

  19. Ticket change [665f3572a9] (rid 102703) by ferrieux on 2008-11-09 04:17:58:

    1. icomment:
      
      
      File Added - 300680: srv.tcl
      
      Typo in previous comment: client connects and sends _10_ lines.
      
      
      File Added: srv.tcl
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  20. Ticket change [421dc139b1] (rid 116305) by ferrieux on 2008-11-09 05:10:57:

    1. icomment:
      Hmm, just noticed that in the nonzero-initial-pause case (ie when we start reading long after the client has closed), even the first [gets] on the server was empty, and EOF. That makes the bug even nastier.
      
      Single-stepping into tclWinSock.c/TcpInputProc shows that even the first recv() is empty, meaning the loss of queued input happens in the OS. Will have to retry with two PCs, because it could be a property of Windows 'loopback' interface (which is not a true network interface, ask Wireshark).
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  21. Ticket change [c78a06dd2d] (rid 121947) by ferrieux on 2008-11-09 05:49:26:

    1. icomment:
      OK just tested with a real network interface (two PCs over wi-fi with a router).
      Result:
       - behavior is the same (!)
       - WireShark shows that the client indeed does a 'short write' (just the first of the 10 lines)
       - This doesn't make it normal for the server to discard that single line.
      So.. do we have 2 bugs instead of 1 ?
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  22. Ticket change [dc1720e3c3] (rid 108069) by ferrieux on 2008-11-09 06:06:56:

    1. icomment:
      OK got it, guys :-)
      The key here is whether the client does an explicit [close] of the socket before exiting.
      If it does, the whole OS socket buffer is actually sent over the wire, *and* a FIN TCP packet ends the stream.
      If it doesn't, the stream is truncated (depending on the speed of things), *and* an RST TCP packet goes out on the truncation.
      This RST in turn wreaks havoc in the receiver.
      So a first action should be to make sure Tcl finalizers do the same thing as [close].
      A second action would be to decide whether it is legal for the receiveing OS to discard input on an RST.
      
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  23. Ticket change [4815ff80fd] (rid 99824) by ferrieux on 2008-11-09 17:34:51:

    1. icomment:
      For the first action, here is what's happening:
      The TcpCloseProc is called during interp finalization, *but* it contains the test:
      
      /*
      * Check that WinSock is initialized; do not call it if not, to prevent
      * system crashes. This can happen at exit time if the exit handler for
      * WinSock ran before other exit handlers that want to use sockets.
      */
      if (SocketsEnabled()) ...
      
      so, I assume we're being hit by this situation: SocketExitHandler() was called too early, before individual sockets could be closed by the generic TclFinalizeIOSubsystem(). The result is a WSACleanup() in mid-life of all open sockets, hence the RST.
      
      Now to look into the order of finalizations to see how to circumvent this ;-)
      
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  24. Ticket change [a192677ef0] (rid 109745) by ferrieux on 2008-11-17 06:49:20:

    1. icomment:
      OK, here is a first report on my analysis.
      
      The problem is that SocketExitHandler is registered among the process-wide handlers, which are called early in Tcl_Finalize, while the closeProc is called in FinalizeIOSubsystem which is part of the later per-thread cleanup.
      Now what's peculiar is that FinalizeIOSubsystem also calls "TclpFinalizeSockets" which is the channeldriver-guts part of the cleanup in SocketExitHandler...
      
      I'm not sure (euphemism) I understand this state of affairs (especially the redundant call of TclpFinalizeSockets on the main thread), however here is how I'd fix it:
      
         - remove entirely the process-wide handler concerning sockets
         - instead enrich TclpFinalizeSockets with a client-counting scheme keeping track of how many threads "with socket interest" remain
         - when this count drops to zero, do the rest of what is currently in SocketExitHandler: UnregisterClass and WSACleanup.
      
      Does this feel correct ?
      Any hint of a definition of "with socket interest" ?
      
      -Alex
      
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  25. Ticket change [160da92c24] (rid 124662) by dgp on 2008-12-31 22:27:33:

    1. assignee changed to: "ferrieux"
    2. icomment:
      
      ferrieux appears to be tracking
      down bugs similar to this one.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. username: "dgp"
  26. Ticket change [fec4c421ee] (rid 108644) by ferrieux on 2009-01-04 04:27:18:

    1. icomment:
      Thanks for diagnosing my split-brain condition Don :-)
      The other bug, 2446662, appeared wildly different in the beginning, but apart from that I have no good excuses...
      Now let's separate the issues this way: here we'll fix the finalization problem, and the RST generation.
      On 2446662 we'll take care of the race condition when receiving an RST.
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  27. Ticket change [4671bdc3d7] (rid 99521) by ferrieux on 2009-01-06 00:30:39:

    1. icomment:
      Further analysis shows that WSACleanup() could be omitted altogether.
      But before resorting to such extremes, I'd like to understand comments saying that Tcl_FinalizeThread makes the IO subsystem unavailable: it is just the channels of this thread+interp, or the whole IO subsystem ? If the latter, how are things supposed to work with the Thread extension spawning several threads+interps, each with several opened channels at [exit]-time ?
      
      In an idea world, we'd have 3 categories of exit handlers called in this order:
         (a) "early" process-wide stuff
         (b) thread-specific handlers, for each thread in turn (pthread_atexit)
         (c) "late" process-wide stuff
      
      Currently the WSACleanup occurs in (a) and (b) (!), I'd first shift it to (c).
      The only problem being that the (c) class currently is static (no CreateXXHandler API).
      Do you agree on this picture ?
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  28. Ticket change [a0999f6d9f] (rid 96838) by ferrieux on 2009-01-07 07:00:03:

    1. icomment:
      
      
      File Added - 308110: fin.patch
      
      The attached patch introduces a new queue of "late exit handlers", with the associated public creation/deletion API.
      This API is then used in tclWinSock.c in lieu of the "early exit handler" for Winsock finalization.
      File Added: fin.patch
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  29. Add attachment "fin.patch" [8006a07ce4] (rid 97662) by ferrieux on 2009-01-07 07:00:03.

  30. Ticket change [c436bb6c4f] (rid 111806) by ferrieux on 2009-01-14 04:51:31:

    1. icomment:
      
      
      File Added - 309031: fin2.patch
      
      Updating the patch so that the new functions handling late handlers get MODULE_SCOPE status instead of stubs, as discussed on the chat with dkf.
      File Added: fin2.patch
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  31. Add attachment "fin2.patch" [cf4e6e47ae] (rid 112954) by ferrieux on 2009-01-14 04:51:31.

  32. Ticket change [8ada706319] (rid 127458) by ferrieux on 2009-01-27 07:32:27:

    1. icomment:
      Patch committed.
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  33. Ticket change [81dadc80ee] (rid 117122) by ferrieux on 2009-01-27 07:32:28:

    1. closedate changed to: "2009-01-27T00:32:28"
    2. closer changed to: "ferrieux"
    3. icomment:
      
      
      allow_comments - 1
      
      
      
    4. login: "ferrieux"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "ferrieux"
  34. Ticket change [974f7f7700] (rid 106483) by dgp on 2009-01-27 10:35:55:

    1. assignee changed to: "dgp"
    2. icomment:
      
      
      allow_comments - 0
      
      
      claiming in order to test and
      verify backports.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. status changed to: "Open"
    6. username: "dgp"
  35. Ticket change [e0726f581b] (rid 115195) by dgp on 2009-01-28 01:06:44:

    1. icomment:
      
      There are two commits to 
      tclWinSock.c on 2009-01-26. 
      Do I need to backport both
      to core-8-4-branch to fix
      this bug?  Or just one?
      Which?
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  36. Ticket change [6878a7a553] (rid 103075) by ferrieux on 2009-01-28 06:03:10:

    1. icomment:
      The ChangeLog entries document which fixes what.
      Of course you can consider the two patches as orthogonal: one is about not generating RSTs on exit, the other about not raising an error on receiving them from the peer.
      But I think both the current bug and 2446662 deserve fixing in all versions.
      So I suggest to backport both. 
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  37. Ticket change [d0598f0258] (rid 113163) by dgp on 2009-01-28 10:36:24:

    1. icomment:
      
      Yeah, I can read the ChangeLog.
      
      If what was written there were
      enough for me to understand, I 
      would not have asked the question.
      Writing it again does not help me.
      
      Let me try again.  Which patch will
      make the failing scripts in this bug
      report stop failing?  Do I need both
      to achieve that?  Or will just one
      do it?  Which one?
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  38. Ticket change [d565c092b4] (rid 123617) by ferrieux on 2009-01-28 14:24:51:

    1. icomment:
      *This* bug report is fixed by the second patch, the one about WSACleanup and late exit handlers.
      The bulk of the patch is in tclEvent.c, the tclWinSock.c part is just a one-line change.
      
      Please tell me what is unclear about it in the ChangeLog, given that this bug's comments are pretty verbose about these notions.
      
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  39. Ticket change [6793ecc700] (rid 102913) by dgp on 2009-04-28 03:16:23:

    1. priority changed to: "9 Immediate"
  40. Ticket change [18d1a1e596] (rid 122727) by dgp on 2009-04-28 03:24:25:

    1. assignee changed to: "ferrieux"
  41. Ticket change [034f2e7199] (rid 119804) by ferrieux on 2009-04-28 05:20:11:

    1. icomment:
      Backported to 8.[45] branches.
      Closing without test suite additions, because the fix for related bug 2446662 zeroes the probability of occurrence of this bug. Truly detecting the absence of RST now would involve an external tool.
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  42. Ticket change [d485c36a82] (rid 123459) by ferrieux on 2009-04-28 05:20:12:

    1. closedate changed to: "2009-04-27T22:20:12"
    2. closer changed to: "ferrieux"
    3. status changed to: "Closed"
  43. Ticket change [84fb8e7969] (rid 131243) by dgp on 2009-04-28 08:48:19:

    1. icomment:
      
      I did not appreciate until reading your
      commit message that these backports
      included a significant new bit of internal
      infrastructure to support "late exit handlers".
      
      Now that you experts have a clear understanding
      of the bug, is there really no way to fix it on
      the 8.4 branch without doing that?
      
      From my original perspective (possibly completely
      wrong) the program that is failing is the server
      program, since it is closing a socket before
      reading all the data on it, and losing data as
      a result.  The server program isn't in the process
      of exiting when this failure happens, so
      it's not apparent to me that fixing the (part of the)
      bug (that most concerns me) really needs significant
      revisions to the shutdown sequence.
      
      We've revised the shutdown sequence before.
      We almost always mess something up in addition
      to fixing up whatever drove the change in the
      first place.  We have no more 8.4 releases to test,
      tweak and correct.  There's only one Final one
      to go, and the description (*) of this backport
      makes me nervous.
      
      So, in my fantasy, I want a Final 8.4.20 that
      1) fixes this bug; and 2) doesn't need big
      revisions to the exit sequence to do it.  Is this
      too much to hope for?
      
      (*) I'm only going by the description.  Haven't
      reviewed even one line of code.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  44. Ticket change [b0a581527e] (rid 98022) by ferrieux on 2009-04-28 13:52:59:

    1. icomment:
      Please note that this was thoroughly covered in the tracker comments (ca. 20090107) though ;-)
      
      Anyway, the late exit handler mechanism is here to delay the winsock cleanup call until after all sockets have been closed, with the final goal of preventing the *sending* of an RST on Tcl exit. Notice that "server" and "client" are interchangeable here; it's more a question of who's sending the RST and who's barfing on receiving it.
      
      Since 2446662 fixes the receive side, and was committed before this one on all three branches, it means that a Tcl peer receiving the RST will no longer raise an error. But it still will discard queued input data after it got the RST (because that's the RST's semantics in the kernel stack). 
      
      Hence (1) I exaggerated when I said this fix was not unit-testable (the very test case that was sometimes failing is now working reliably -- but building a 100% failing case is a lot of work), and (2) I think the "late WSACleanup" is the only way to prevent sending those nasty RSTs on exit (which may also disrupt a non-Tcl peer).
      
      Of course a contorted hack could involve doing this late cleanup by making the whole interp teardown function completely platform-specific, and hard-code the winsock cleanup near the end in the win32 case. But I fail to see the advantage of such an approach over the cleaner and generic notion of late exit handlers, which allows any extension to use the same semantics (and has been committed to HEAD for some time with no ill effect...).
      
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  45. Ticket change [7afcd01575] (rid 90435) by dgp on 2009-04-28 20:43:05:

    1. assignee changed to: "dgp"
    2. icomment:
      
      Thanks for considering my comments, and the reply.
      
      Let's leave the fix on the 8-4-branch.  I'm re-opening
      this, simply as a reminder that I'd like to review the
      patch before releasing 8.4.20.
      
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. status changed to: "Open"
    6. username: "dgp"
  46. Ticket change [d10bc08df2] (rid 113285) by ferrieux on 2011-08-19 22:59:56:

    1. icomment:
      Lowering to prio 8, since it's been committed for long.
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  47. Ticket change [127f373c61] (rid 95313) by ferrieux on 2011-08-19 23:00:03:

    1. priority changed to: "8"