<i>Crash when using a channel transformation on TCP client socket</i> status still Open with 3 other changes
by
.
D 2023-03-07T06:53:28.010
J icomment Although\sTcl\sshould\snever\scrash\sfrom\sanything\syou\sdo\sat\sthe\sscripting\slevel,\sthere\sare\sseveral\sproblems\swith\syour\scode\swhich\sI\spresume\syou\shave\sfixed\sin\syour\sscript\sbut\supdated\sthe\sticket.\r\n\r\nIn\sthe\s`readcount`\sproc,\r\n\r\n-\sthere\sis\sa\s`break`\soutside\sof\sa\sloop\swhich\scauses\sthe\sevent\shandler\sto\sabort.\sI\spresume\sthat\sshould\sbe\sa\sreturn.\r\n-\sthe\s`$readcount\s<=\s0`\scheck\sshould\sbe\s`$readcount\s<\s0`\ssince\sgetting\sback\san\sempty\sline\sis\sperfectly\skosher.\sIn\sparticular\snote\syour\s`puts\sHello\\r\\n`\sis\ssending\s**two**\snewlines,\sone\sexplicit\sand\sone\sbecause\sof\sthe\s`\\r\\n`.\sSo\syou\swill\sget\sback\san\sempty\sline\sfrom\sthe\sserver.\r\n-\sThe\s`set\s:status\s"closed"`\sline\sis\smissing\sa\s`:`\s-\sshould\sbe\s`::status`\r\n-\sMoreover,\sstrictly\sspeaking\syou\sshould\salso\sset\s::msg\sin\sthere\sin\scase\sthe\r\nserver\scloses\swithout\ssending\sanything\sback\s(the\svwait\sis\swaiting\son\s::msg)\r\n-\sIn\scase\sof\sEOF\swithout\sreceiving\sany\slines,\sthe\shandler\scloses\sthe\ssocket\sand\sthe\schan\spop\sis\sattempted\son\sa\sclosed\ssocket.\sAgain\sthis\sis\sonly\sin\sthe\scase\sthe\sserver\scloses\swithout\ssending\sanything.\r\n\r\nIn\sany\scase,\sI\scould\snot\sreproduce\sthe\scrash.\sWith\syour\sscript,\sI\ssimply\sget\sTcl\sexceptions,\sas\sexpected.\sWith\smy\schanges\s(see\sscript\sbelow),\sI\sget\sa\sprint\sout\r\n\r\n```\r\nStatus\sconnected\r\nHello\r\nConnection\saborted\r\nGot\sclosed\r\nDONE\r\n```\r\n\r\nThis\sis\sirrespective\sof\swhether\sthe\supdate\sis\scommented\sor\snot.\s\r\n\r\nMy\sscript\sis\sbelow,\splease\stry\sand\ssee\sif\sthe\scrash\sis\sreproduced\son\syour\ssystem\swith\smy\sscript:\r\n\r\n```\r\nlappend\sauto_path\sd:/tcl/lib\r\npackage\srequire\stcl::transform::observe\r\n\r\nproc\swritable\s{sock}\s{\r\n\s\s\s\schan\sevent\s$sock\swritable\s{}\r\n\s\s\s\schan\sconfigure\s$sock\s-translation\s{crlf\sbinary}\s-blocking\s0\s-buffering\sfull\s-encoding\sbinary\r\n\s\s\s\schan\sevent\s$sock\sreadable\s[list\sreadable\s$sock]\r\n\s\s\s\sset\s::status\s"connected"\r\n}\r\n\r\nproc\sreadable\s{sock}\s{\r\n\s\s\s\sset\sreadCount\s[chan\sgets\s$sock\sline]\r\n\s\s\s\sif\s{$readCount\s<\s0}\s{\r\n\s\s\s\s\s\s\s\sif\s{[eof\s$sock]}\s{\s\r\n\s\s\s\s\s\s\s\s\s\s\s\sputs\s"Connection\saborted"\r\n\s\s\s\s\s\s\s\s\s\s\s\s#\sclose\s$sock\r\n\s\s\s\s\s\s\s\s\s\s\s\schan\sevent\s$sock\sreadable\s{}\r\n\s\s\s\s\s\s\s\s\s\s\s\sset\s::msg\s"closed"\r\n\s\s\s\s\s\s\s\s\s\s\s\sreturn\r\n\s\s\s\s\s\s\s\s}\r\n\s\s\s\s\s\s\s\s#\swe\sdon't\shave\sa\sfull\sline\syet\s-\swait\sfor\snext\schan\sevent\r\n\s\s\s\s\s\s\s\sreturn\r\n\s\s\s\s}\r\n\s\s\s\sset\s::msg\s$line\r\n}\r\n\r\nset\ssock\s[socket\s-async\slocalhost\s4400]\r\nchan\sevent\s$sock\swritable\s[list\swritable\s$sock]\r\nvwait\s::status\r\nputs\s"Status\s$status"\r\ntcl::transform::observe\s$sock\sstdout\s""\r\n\r\nputs\s$sock\s"Hello"\r\nflush\s$sock\r\n\r\nvwait\s::msg\r\nputs\s"Got\s$msg"\r\n#\supdate\s;#-\savoids\scrash\r\nchan\spop\s$sock\r\n\r\nafter\s100\s{set\s::forever\s1}\r\nvwait\sforever\s;#\scrashes\shere\r\n\r\nclose\s$sock\r\nputs\sDONE\r\n\r\n```
J login apnadkarni
J mimetype text/x-markdown
K ea69b0258a9833cb61ada42d1fc742d90aec04d0
U apnadkarni
Z 83cad10ca0f6c43589b7af962d9b0f2b