Manifest of check-in
[521b7229c4]
- This is a change for a problem which is pretty much impossible to test
for in the testsuite, as it is a race condition on a problem with
Windows and as such cannot be reliably induced from the Tcl side,
script nor C.
The problem affects only sockets which are opened -async.
At the time of the socket's creation the core will remember this fact
in the SocketState flags (SOCKET_ASYNC_CONNECT <SAC>) and in the
events to look for with select (FD_CONNECT).
Then, to handle the possiblity that the script writes to or read from
the socket before the connection has completed the driver functions
Tcp(Input|Output)Proc check for the flag, and if it is still set enter
WaitForSocketEvent (FD_CONNECT) <WFSE> to sync-wait for the connection
before continuing to actually read/write.
Unfortunately Windows sometimes deigns to not deliver FD_CONNECT,
skipping directly to FD_READ|WRITE. When that happens the unmodified
WFSE gets stuck in WFSO, and hangs the entire Tcl process.
The core actually already has code to deal with that situation, in
part. This code is found in the SOCKET_MESSAGE branch of the big
switch in SocketProc(). When it finds <SAC> in the flags not reset by
an FD_CONNECT event it unconditionally clears the flag and forces an
FD_WRITE on other parts (My change adds a comment to the location in
question, as marker).
This code works for when Windows delivers the first event before the
script manages to read/write from the new socket, because then the
driver functions will see the cleared flag and not enter WFSE to wait
for FD_CONNECT in the first place.
However, if the script was fast enough to already be in the WFSE
waiting for FD_CONNECT then the main thread is stuck and the change my
by SocketProc() does not help.
The commit here fixes that issue by extending WFSE to recognize the
reset of SAC by SocketProc() as a valid break condition when it waits
for FD_CONNECT, thus preventing it from getting stuck.
by
andreask on
2014-03-08 00:21:59.
B 5145f9b67365b976e0cfb48ee865aa77d8cd336d
C This\sis\sa\schange\sfor\sa\sproblem\swhich\sis\spretty\smuch\simpossible\sto\stest\nfor\sin\sthe\stestsuite,\sas\sit\sis\sa\srace\scondition\son\sa\sproblem\swith\nWindows\sand\sas\ssuch\scannot\sbe\sreliably\sinduced\sfrom\sthe\sTcl\sside,\nscript\snor\sC.\n\nThe\sproblem\saffects\sonly\ssockets\swhich\sare\sopened\s-async.\n\nAt\sthe\stime\sof\sthe\ssocket's\screation\sthe\score\swill\sremember\sthis\sfact\nin\sthe\sSocketState\sflags\s(SOCKET_ASYNC_CONNECT\s<SAC>)\sand\sin\sthe\nevents\sto\slook\sfor\swith\sselect\s(FD_CONNECT).\n\nThen,\sto\shandle\sthe\spossiblity\sthat\sthe\sscript\swrites\sto\sor\sread\sfrom\nthe\ssocket\sbefore\sthe\sconnection\shas\scompleted\sthe\sdriver\sfunctions\nTcp(Input|Output)Proc\scheck\sfor\sthe\sflag,\sand\sif\sit\sis\sstill\sset\senter\nWaitForSocketEvent\s(FD_CONNECT)\s<WFSE>\sto\ssync-wait\sfor\sthe\sconnection\nbefore\scontinuing\sto\sactually\sread/write.\n\nUnfortunately\sWindows\ssometimes\sdeigns\sto\snot\sdeliver\sFD_CONNECT,\nskipping\sdirectly\sto\sFD_READ|WRITE.\sWhen\sthat\shappens\sthe\sunmodified\nWFSE\sgets\sstuck\sin\sWFSO,\sand\shangs\sthe\sentire\sTcl\sprocess.\n\nThe\score\sactually\salready\shas\scode\sto\sdeal\swith\sthat\ssituation,\sin\npart.\sThis\scode\sis\sfound\sin\sthe\sSOCKET_MESSAGE\sbranch\sof\sthe\sbig\nswitch\sin\sSocketProc().\sWhen\sit\sfinds\s<SAC>\sin\sthe\sflags\snot\sreset\sby\nan\sFD_CONNECT\sevent\sit\sunconditionally\sclears\sthe\sflag\sand\sforces\san\nFD_WRITE\son\sother\sparts\s(My\schange\sadds\sa\scomment\sto\sthe\slocation\sin\nquestion,\sas\smarker).\n\nThis\scode\sworks\sfor\swhen\sWindows\sdelivers\sthe\sfirst\sevent\sbefore\sthe\nscript\smanages\sto\sread/write\sfrom\sthe\snew\ssocket,\sbecause\sthen\sthe\ndriver\sfunctions\swill\ssee\sthe\scleared\sflag\sand\snot\senter\sWFSE\sto\swait\nfor\sFD_CONNECT\sin\sthe\sfirst\splace.\n\nHowever,\sif\sthe\sscript\swas\sfast\senough\sto\salready\sbe\sin\sthe\sWFSE\nwaiting\sfor\sFD_CONNECT\sthen\sthe\smain\sthread\sis\sstuck\sand\sthe\schange\smy\nby\sSocketProc()\sdoes\snot\shelp.\n\nThe\scommit\shere\sfixes\sthat\sissue\sby\sextending\sWFSE\sto\srecognize\sthe\nreset\sof\sSAC\sby\sSocketProc()\sas\sa\svalid\sbreak\scondition\swhen\sit\swaits\nfor\sFD_CONNECT,\sthus\spreventing\sit\sfrom\sgetting\sstuck.\n
D 2014-03-08T00:21:59.686
F generic/tcl.h f522f635046f5c9bc74cc910bf1938605286f23a
F generic/tclBasic.c ca0d96f141cb6d528010f7ae398349cf23f55fdf
F generic/tclEncoding.c 526a506b8b74b08c8de83a03a2938e87e32e903c
F generic/tclExecute.c 44ff90974b7a9106cba95285e675f390a1a88908
F generic/tclIO.c fab5b0b7052fbe8777f12e0e451a9efe095b1f6d
F generic/tclInt.h 9f42084e6e6f85a11970040540fc42a1aff0f61d
F generic/tclListObj.c 3d0412775d3d200eab6a159b2e2087ad23990c5d
F generic/tclNotify.c bada4bc2f860758a60810040513c06f10d53e06a
F library/init.tcl 3d9a25f97686734bbf55d3a13388165c12c348d4
F library/parray.tcl a0b1bd4e68dce1768d3c5e0d3c7b31e28021d3ba
F library/tcltest/pkgIndex.tcl 045ecb9e24608694c6ec88d252012239c6dd6b73
F library/tcltest/tcltest.tcl 0026f9e0fea4c0538515690a618a5ffd378c865e
F tests/io.test 561d92b7e2d9a3f3f6d92c8a913de9d3fefe5335
F tests/namespace.test 96bd1d62b1c7f86f462a87c76492b7605783a703
F unix/Makefile.in 66cd270bb4c5724f183f63687b81cf9bb8653fae
F unix/configure 41e94b2896c8fa27117f44255466d53722ffa07f x
F unix/tcl.m4 0223243a996c230fdd69cfd601c3eb97e2ac7d69
F unix/tclConfig.sh.in 6c2f3bf7285bc8ae34a86fbb03abf13554cea428
F unix/tclUnixInit.c 0482cc7eb84bec324530730b02751c40ba88def3
F win/Makefile.in ba4b95ea49dffdfe311164922f95c0e21e30f487
F win/configure 6796c6d081cd7913a5c2708e4146f26f9bd4df77 x
F win/configure.in 514a64b85283699f518998638c289afd1d9273b2
F win/makefile.vc 452223f7f2fc94392fcbc685d15274b58c624220
F win/tclConfig.sh.in 981fb036808da6e05a9be59368c8e133232deb91
F win/tclWin32Dll.c 40b0bec3e0e2bf6c89ed8ba6768ce84f57e2fb78
F win/tclWinChan.c a288fcf8f36fe3166a3be276200b93b41eb56afd
F win/tclWinInit.c 6a9a678e2d20d46529916a93321f5d4081fbee5d
F win/tclWinInt.h b6afacd04337b999218a18d79791fcee6b112501
F win/tclWinSerial.c d18f2a14fba23d937887106b398904c20013fc06
F win/tclWinSock.c 12cffa5d87341c7b6e08cf465c67df5b6d48368b
F win/tclsh.exe.manifest.in 11f0700eb0759f46f6c3a3a51ae529698a122d8d
F win/tclsh.rc 967eeedb2ed14f07b6e59294a0f9a0e63ee0d8fd
P 279154c448655a04024d9da28bc5ba17744b4d5e
R 030992bc3da9c7b579f94819c3f728d9
T *branch * win-sock-async-connect-race-fix
T *sym-win-sock-async-connect-race-fix *
T -sym-core-8-5-branch *
U andreask
Z 8a733a85bca4ec80638336f1de6c3e30