Skip to content
Tcl Source Code Artifact [f54756de6b]
Login

Artifact [f54756de6b]

Artifact f54756de6b6805694e94fe240c92cbf95494a719d03703012b6be12aac46e208:

Ticket change [f54756de6b] - New ticket [080f846fd58958ef|080f846fd5] <i>Channel system generating writable events BEFORE channel is open (refchan)</i>. by apnadkarni on 2024-03-28 11:44:21.
D 2024-03-28T11:44:21.451
J assignee nobody
J closer nobody
J cmimetype text/x-markdown
J comment A\sscript\smay\sopen\sa\snon-blocking\schannel\sand\sregister\san\s"writable"\sevent\shandler\sto\sbe\scalled\swhen\sthe\schannel\sis\sopen.\sThis\sworked\sfor\srefchans\sas\swell\sin\s8.6\sbut\sin\s9.0,\sthe\shandler\sis\sinvoked\sBEFORE\sthe\schannel\sis\sactually\sopen.\sThe\sculprit\sis\sthe\s[following](https://core.tcl-lang.org/tcl/file?ci=692ac81a3a01d582&name=generic/tclIO.c&ln=8761-8770)\scode\sin\stclIO.c\r\n\r\n```\r\nif\s(statePtr->interestMask\s&\sTCL_WRITABLE\r\n\t\t&&\sGotFlag(statePtr,\sCHANNEL_NONBLOCKING)\r\n\t\t&&\s!GotFlag(statePtr,\sBG_FLUSH_SCHEDULED))\s{\r\n\t\s\s\s\s/*\r\n\t\s\s\s\s\s*\sRestart\sthe\stimer\sin\scase\sa\schannel\shandler\sreenters\sthe\sevent\sloop\r\n\t\s\s\s\s\s*\sbefore\sUpdateInterest\sgets\scalled\sby\sTcl_NotifyChannel.\r\n\t\s\s\s\s\s*/\r\n\t\s\s\s\sstatePtr->timer\s=\sTcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME,\r\n\t\tChannelTimerProc,chanPtr);\r\n\t\s\s\s\sTcl_NotifyChannel((Tcl_Channel)\schanPtr,\sTCL_WRITABLE);\r\n```\r\n\r\nThe\sabove\swas\sadded\spost-8.6\sto\s`ChannelTimerProc`\sin\s[d0dd6d19a4](https://core.tcl-lang.org/tcl/info/d0dd6d19a4)\sas\sa\sfix\sfor\sa\s[ticket](https://core.tcl-lang.org/tcl/tktview/de232b49f2).\sNo\smatter\sthe\smotivation,\sthis\sfragment\sseems\sincorrect\sor\sincomplete\sto\sme.\sUnder\sno\scircumstances\sshould\sa\sfile\sevent\swritable\scallback\sbe\sinvoked\sunless\sthe\schannel\sis\sactually\sopen\s(writable)\sand\sthe\sabove\sdoes\snot\smake\sthat\scheck.\r\n\r\nThe\simpacted\scase\sdescribed\sbelow\sinvolves\srefchans\sbecause\sthe\srefchan\sinfrastructure\suses\stimers\sto\sgenerate\sevents\sbut\sI\ssuspect\sit\scould\salso\saffect\sordinary\schannels\sthat\sregister\stimers\sto\sdetect\s(for\sexample)\sconnection\stime\souts.\r\n\r\nI\sran\sinto\sthe\sabove\sporting\stwapi\sto\s9.0.\sTwapi's\sTLS\ssockets\sare\simplemented\sas\srefchans\swrapping\sTcl\ssockets.\sThe\sissue\sI'm\sseeing\sis\sthe\sfollowing\stest\scase:\r\n\r\n```\r\n\s\s\s\sset\sso\s[twapi::tls_socket\s-async\swww.example.com\s443]\r\n\s\s\s\sfconfigure\s$so\s-blocking\s0\r\n\s\s\s\sfileevent\s$so\swritable\s[list\sapply\s{{chan}\s{\r\n\s\s\s\s\s\s\s...chan\sis\snot\sactually\sopen\swhen\sthis\sis\scalled\ssince\sconnection\shas\snot\scompleted\r\n\s\s\s\s}}\s$so]\r\n\s\s\s\svwait\s...\r\n```\r\n\r\n`tls_socket`\sis\simplemented\sas\sa\sreflected\schannel.\sIn\s8.6,\sthere\swas\sno\s"automatic"\stimer\sbased\swrite\sevent\sgeneration\sand\sthus\sthe\scallback\swas\sinvoked\sonly\son\sconnection\scompletion.\sWith\sthe\sabove\schange,\sthe\scallback\sis\sinvoked\sfrom\sthe\stimer\scode\swithout\sany\schecks\sthat\sthe\sreflected\schannel\sis\sactually\sopen.\r\n\r\nA\ssimple\stest\scase\sis\snot\seasy\sto\screate\ssince\sit\sinvolves\stiming\s(the\sconnection\sshould\snot\scomplete\sbefore\sthe\stimer)\sand\simplementation\sof\sa\svirtual\schannel\sbut\sthe\sabove\scode\sseems\sobviously\swrong\sto\sme\sin\sthat\sit\sdoes\snot\scheck\swhether\schannel\sis\sactually\sopen.
J foundin 9.0
J is_private 0
J login apnadkarni
J priority 5\sMedium
J private_contact 9546e9877f1a8899e25a89082561ee694e7fb402
J resolution None
J severity Important
J status Open
J submitter apnadkarni
J subsystem 25.\sChannel\sSystem
J title Channel\ssystem\sgenerating\swritable\sevents\sBEFORE\schannel\sis\sopen\s(refchan)
J type Bug
K 080f846fd58958efeaa5e2247622dc0ee7fa1ff7
U apnadkarni
Z 2aa63e3a48d9fac5a483b10e5b7f6512