.
D 2014-03-21T14:43:56.917
J assignee nobody
J closer nobody
J cmimetype text/plain
J comment It\sturns\sout\sthat\sunder\ssome\sLinux\skernels\s(including\srhel5\sand\srhel6),\sselect(2)\sdoes\snot\sreturn\sas\swritable\ssockets\swhich\shave\sbeen\sclosed\sfrom\sthe\sother\send,\seven\sthough\scalls\sto\ssendmsg\s(which\sis\swhat\sPOSIX\sgives\sas\sthe\simplied\soutput\sfunction\sfor\ssockets)\swould\snot\sblock.\s\sThis\scan\sresult\sin\sTcl's\sleaking\ssocket-descriptors.\r\n\r\nSource\scode\sfor\sthe\stests\sbelow\sis\savailable\sat\s<https://www.azazel.net/~azazel/tcl_async_flush/>.\r\n\r\nCompare\sthis\ssnippet:\r\n\r\n\s\s$\slsb_release\s-d\r\n\s\sDescription:\s\s\s\sRed\sHat\sEnterprise\sLinux\sServer\srelease\s6.5\s(Santiago)\r\n\s\s$\suname\s-r\r\n\s\s2.6.32-358.23.2.el6.x86_64\r\n\s\s$\sgcc\s-Wall\s-W\s-pedantic\s-std=c99\s-O3\s-D_XOPEN_SOURCE=600\sselect_test.c\s-o\sselect_test\r\n\s\s$\s./select_test\slocalhost\s12345\sncat\r\n\s\s_system:\sncat\s-l\s12345\s&\ssleep\s1\r\n\s\s_connect:\sconnected\sto\slocalhost:12345.\r\n\s\s_select:\sselect\s=\s1,\sFD_ISSET\s(3,\s&wfds)\s==\s1.\r\n\s\s_system:\spkill\s-x\sncat;\ssleep\s1\r\n\s\s_select:\sselect\s=\s1,\sFD_ISSET\s(3,\s&wfds)\s==\s1.\r\n\s\s_send:\ssendmsg\s0\sreturned:\s163840\r\n\s\s_send:\ssendmsg\s1\sfailed:\sBroken\spipe\r\n\s\s_select:\sselect\s=\s0,\sFD_ISSET\s(3,\s&wfds)\s==\s0.\r\n\r\nto\sthis\sone:\r\n\r\n\s\s$\slsb_release\s-d\r\n\s\sDescription:\s\s\s\sDebian\sGNU/Linux\stesting\s(jessie)\r\n\s\s$\suname\s-r\r\n\s\s3.10-2-amd64\r\n\s\s$\sgcc\s-Wall\s-W\s-pedantic\s-std=c99\s-O3\s-D_XOPEN_SOURCE=600\sselect_test.c\s-o\sselect_test\r\n\s\s$\s./select_test\slocalhost\s12345\snc\r\n\s\s_system:\snc\s-l\s12345\s&\ssleep\s1\r\n\s\s_connect:\sconnected\sto\slocalhost:12345.\r\n\s\s_select:\sselect\s=\s1,\sFD_ISSET\s(3,\s&wfds)\s==\s1.\r\n\s\s_system:\spkill\s-x\snc;\ssleep\s1\r\n\s\s_select:\sselect\s=\s1,\sFD_ISSET\s(3,\s&wfds)\s==\s1.\r\n\s\s_send:\ssendmsg\s0\sreturned:\s656640\r\n\s\s_send:\ssendmsg\s1\sfailed:\sBroken\spipe\r\n\s\s_select:\sselect\s=\s1,\sFD_ISSET\s(3,\s&wfds)\s==\s1.\r\n\r\nNext\sI\srun\sa\sserver\swhich\saccepts\sconnexions\sand\sthen\swrites\slong\slines\sto\sthem,\sand\sa\sclient\swhich\sconnects,\spauses\sto\sgive\sthe\sserver\sa\schance\sto\sfill\sthe\ssend\sbuffers\son\sits\ssocket,\sstarts\sreading\sfor\sa\swhile\sand\sdisconnects.\s\sThe\sclient\sdoes\sthis\sa\slimited\snumber\sof\stimes\sand\sthen\sexits.\s\sAfterwards\sI\srun\slsof\sagainst\sthe\sserver.\r\n\r\n\s\s$\s/space/azazel/tcl8.5.15/bin/tclsh8.5\sserver.tcl\s2300\s&\r\n\s\s[1]\s4886\r\n\s\s$\s/space/azazel/tcl8.5.15/bin/tclsh8.5\sclient.tcl\slocalhost\s2300\r\n\s\s$\slsof\s-p\s4886\s-n\s-P\s2>/dev/null\r\n\s\sCOMMAND\s\s\sPID\s\s\s\sUSER\s\s\sFD\s\s\sTYPE\s\s\s\s\sDEVICE\sSIZE/OFF\s\s\s\s\s\s\sNODE\sNAME\r\n\s\stclsh8.5\s4886\sjsowden\s\scwd\s\s\s\sDIR\s\s\s\s\s\s253,2\s\s\s\s\s4096\s\s\s36449390\s/space/azazel/tmp/tcl_async_flush\r\n\s\stclsh8.5\s4886\sjsowden\s\srtd\s\s\s\sDIR\s\s\s\s\s\s253,0\s\s\s\s\s4096\s\s\s\s\s\s\s\s\s\s2\s/\r\n\s\stclsh8.5\s4886\sjsowden\s\stxt\s\s\s\sREG\s\s\s\s\s\s253,2\s\s\s\s\s8815\s\s\s37227160\s/space/azazel/tcl8.5.15/bin/tclsh8.5\r\n\s\stclsh8.5\s4886\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s\s\s156928\s\s\s\s\s\s\s1885\s/lib64/ld-2.12.so\r\n\s\stclsh8.5\s4886\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s\s1926800\s\s\s\s\s\s\s1886\s/lib64/libc-2.12.so\r\n\s\stclsh8.5\s4886\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s\s\s\s22536\s\s\s\s\s\s\s1986\s/lib64/libdl-2.12.so\r\n\s\stclsh8.5\s4886\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s\s\s599384\s\s\s\s\s\s\s5964\s/lib64/libm-2.12.so\r\n\s\stclsh8.5\s4886\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,3\s\s\s347044\s\s\s\s\s\s\s\s169\s/var/db/nscd/passwd\r\n\s\stclsh8.5\s4886\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s99158576\s\s\s\s\s\s27784\s/usr/lib/locale/locale-archive\r\n\s\stclsh8.5\s4886\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,2\s\s1274890\s\s\s36974995\s/space/azazel/tcl8.5.15/lib/libtcl8.5.so\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s\s0u\s\s\sCHR\s\s\s\s136,602\s\s\s\s\s\s0t0\s\s\s\s\s\s\s\s605\s/dev/pts/602\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s\s1u\s\s\sCHR\s\s\s\s136,602\s\s\s\s\s\s0t0\s\s\s\s\s\s\s\s605\s/dev/pts/602\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s\s2u\s\s\sCHR\s\s\s\s136,602\s\s\s\s\s\s0t0\s\s\s\s\s\s\s\s605\s/dev/pts/602\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s\s3u\s\sIPv4\s1302178374\s\s\s\s\s\s0t0\s\s\s\s\s\s\s\sTCP\s*:2300\s(LISTEN)\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s\s4u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302186289\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s\s5u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302182312\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s\s6u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302197139\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s\s7u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302196702\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s\s8u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302264163\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s\s9u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302212690\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s10u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302250999\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s11u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302353390\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s12u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302324260\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s13u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302326816\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s14u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302345636\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s15u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302432996\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s16u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302369570\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s17u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302382000\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s18u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302416754\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s19u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302442574\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s20u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302438961\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s21u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302505446\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s22u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302545287\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s23u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302536915\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s24u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302585903\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s25u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302557438\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s26u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302571883\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s27u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302600981\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s28u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302606036\scan't\sidentify\sprotocol\r\n\s\stclsh8.5\s4886\sjsowden\s\s\s30u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302612110\scan't\sidentify\sprotocol\r\n\s\s$\skill\s%%\r\n\s\s[1]+\s\sTerminated\s\s\s\s\s\s\s\s\s\s\s\s\s\s/space/azazel/tcl8.5.15/bin/tclsh8.5\sserver.tcl\s2300\r\n\s\s$\s/space/azazel/tcl8.6.1/bin/tclsh8.6\sserver.tcl\s2300\s&\r\n\s\s[1]\s32450\r\n\s\s$\s/space/azazel/tcl8.6.1/bin/tclsh8.6\sclient.tcl\slocalhost\s2300\r\n\s\s$\slsof\s-p\s32450\s-n\s-P\s2>/dev/null\r\n\s\sCOMMAND\s\s\s\sPID\s\s\s\sUSER\s\s\sFD\s\s\sTYPE\s\s\s\s\sDEVICE\sSIZE/OFF\s\s\s\s\s\s\sNODE\sNAME\r\n\s\stclsh8.6\s32450\sjsowden\s\scwd\s\s\s\sDIR\s\s\s\s\s\s253,2\s\s\s\s\s4096\s\s\s36449390\s/space/azazel/tmp/tcl_async_flush\r\n\s\stclsh8.6\s32450\sjsowden\s\srtd\s\s\s\sDIR\s\s\s\s\s\s253,0\s\s\s\s\s4096\s\s\s\s\s\s\s\s\s\s2\s/\r\n\s\stclsh8.6\s32450\sjsowden\s\stxt\s\s\s\sREG\s\s\s\s\s\s253,2\s\s\s\s\s9126\s\s\s40788208\s/space/azazel/tcl8.6.1/bin/tclsh8.6\r\n\s\stclsh8.6\s32450\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s\s\s156928\s\s\s\s\s\s\s1885\s/lib64/ld-2.12.so\r\n\s\stclsh8.6\s32450\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s\s1926800\s\s\s\s\s\s\s1886\s/lib64/libc-2.12.so\r\n\s\stclsh8.6\s32450\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s\s\s\s22536\s\s\s\s\s\s\s1986\s/lib64/libdl-2.12.so\r\n\s\stclsh8.6\s32450\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s\s\s145896\s\s\s\s\s\s\s1887\s/lib64/libpthread-2.12.so\r\n\s\stclsh8.6\s32450\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s\s\s\s91096\s\s\s\s\s\s\s5944\s/lib64/libz.so.1.2.3\r\n\s\stclsh8.6\s32450\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s\s\s599384\s\s\s\s\s\s\s5964\s/lib64/libm-2.12.so\r\n\s\stclsh8.6\s32450\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,3\s\s\s347044\s\s\s\s\s\s\s\s169\s/var/db/nscd/passwd\r\n\s\stclsh8.6\s32450\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,0\s99158576\s\s\s\s\s\s27784\s/usr/lib/locale/locale-archive\r\n\s\stclsh8.6\s32450\sjsowden\s\smem\s\s\s\sREG\s\s\s\s\s\s253,2\s\s1797180\s\s\s40648124\s/space/azazel/tcl8.6.1/lib/libtcl8.6.so\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s\s0u\s\s\sCHR\s\s\s\s136,602\s\s\s\s\s\s0t0\s\s\s\s\s\s\s\s605\s/dev/pts/602\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s\s1u\s\s\sCHR\s\s\s\s136,602\s\s\s\s\s\s0t0\s\s\s\s\s\s\s\s605\s/dev/pts/602\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s\s2u\s\s\sCHR\s\s\s\s136,602\s\s\s\s\s\s0t0\s\s\s\s\s\s\s\s605\s/dev/pts/602\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s\s3r\s\sFIFO\s\s\s\s\s\s\s\s0,8\s\s\s\s\s\s0t0\s1302920286\spipe\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s\s4w\s\sFIFO\s\s\s\s\s\s\s\s0,8\s\s\s\s\s\s0t0\s1302920286\spipe\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s\s5u\s\sIPv4\s1302920300\s\s\s\s\s\s0t0\s\s\s\s\s\s\s\sTCP\s*:2300\s(LISTEN)\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s\s6u\s\sIPv6\s1302920301\s\s\s\s\s\s0t0\s\s\s\s\s\s\s\sTCP\s*:2300\s(LISTEN)\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s\s7u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302960490\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s\s8u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302991225\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s\s9u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302999582\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s10u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1302996445\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s11u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303021832\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s12u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303026730\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s13u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303037627\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s14u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303034803\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s15u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303037144\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s16u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303055527\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s17u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303040280\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s18u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303051215\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s19u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303061492\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s20u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303058139\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s21u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303069747\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s22u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303097499\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s23u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303082333\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s24u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303084992\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s25u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303087033\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s26u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303088580\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s27u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303094229\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s28u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303099862\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s29u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303105973\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s30u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303140515\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s31u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303113400\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s32u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303116737\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s33u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303152668\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s34u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303227072\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s35u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303166233\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s36u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303167227\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s37u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303190255\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s38u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303240333\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s39u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303247365\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s40u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303247820\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s41u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303277650\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s42u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303250926\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s43u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303254036\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s44u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303268472\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s45u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303275087\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s46u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303294151\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s47u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303281716\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s48u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303327290\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s49u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303307061\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s50u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303320536\scan't\sidentify\sprotocol\r\n\s\stclsh8.6\s32450\sjsowden\s\s\s51u\s\ssock\s\s\s\s\s\s\s\s0,6\s\s\s\s\s\s0t0\s1303331253\scan't\sidentify\sprotocol\r\n\r\nWhat\sappears\sto\sbe\shappening\sis\sthat\sthe\sclient\sdisconnects\swhile\sthe\sserver\sis\r\ndoing\sasynchronous\sflushes,\swhich\scauses\sthe\schannel's\soutput\sproc\sto\sreturn\s-1\r\n(tcl8.5.15/generic/tclIO.c,\sFlushChannel,\sll.\s2481ff.):\r\n\r\n\t/*\r\n\t\s*\sProduce\sthe\soutput\son\sthe\schannel.\r\n\t\s*/\r\n\r\n\ttoWrite\s=\sBytesLeft(bufPtr);\r\n\tif\s(toWrite\s==\s0)\s{\r\n\t\s\s\s\swritten\s=\s0;\r\n\t}\selse\s{\r\n\t\s\s\s\swritten\s=\s(chanPtr->typePtr->outputProc)(chanPtr->instanceData,\r\n\t\tRemovePoint(bufPtr),\stoWrite,\s&errorCode);\r\n\t}\r\n\r\n\t/*\r\n\t\s*\sIf\sthe\swrite\sfailed\scompletely\sattempt\sto\sstart\sthe\sasynchronous\r\n\t\s*\sflush\smechanism\sand\sbreak\sout\sof\sthis\sloop\s-\sdo\snot\sattempt\sto\r\n\t\s*\swrite\sany\smore\soutput\sat\sthis\stime.\r\n\t\s*/\r\n\r\n\tif\s(written\s<\s0)\s{\r\n\r\nand\sall\spending\soutput\sto\sbe\sdiscarded\s(tcl8.5.15/generic/tclIO.c,\sFlushChannel,\sll.\s2584ff.):\r\n\r\n\t\s\s\s\s/*\r\n\t\s\s\s\s\s*\sWhen\swe\sget\san\serror\swe\sthrow\saway\sall\sthe\soutput\scurrently\r\n\t\s\s\s\s\s*\squeued.\r\n\t\s\s\s\s\s*/\r\n\r\n\t\s\s\s\sDiscardOutputQueued(statePtr);\r\n\t\s\s\s\scontinue;\r\n\t}\selse\s{\r\n\t\s\s\s\swroteSome\s=\s1;\r\n\t}\r\n\r\nNext\stime\sround\sthe\sloop,\sthe\sbuffer\spointer\sis\sNULL\sand\sthe\sloop\sis\sexited\s(tcl8.5.15/generic/tclIO.c,\sFlushChannel,\sll.\s2469ff.):\r\n\r\n\t/*\r\n\t\s*\sIf\sthe\soutput\squeue\sis\sstill\sempty,\sbreak\sout\sof\sthe\swhile\sloop.\r\n\t\s*/\r\n\r\n\tif\s(bufPtr\s==\sNULL)\s{\r\n\t\s\s\s\sbreak;\t/*\sOut\sof\sthe\s"while\s(1)".\s*/\r\n\t}\r\n\r\nSince\sdata\shave\salready\sbeen\swritten\sduring\sthis\scall,\sthe\swroteSome\sis\strue,\sand\sBG_FLUSH_SCHEDULED\sflag\sis\snot\sreset\s(tcl8.5.15/generic/tclIO.c,\sFlushChannel,\sll.\s2610ff.):\r\n\r\n\s\s\s\s/*\r\n\s\s\s\s\s*\sIf\swe\swrote\ssome\sdata\swhile\sflushing\sin\sthe\sbackground,\swe\sare\sdone.\r\n\s\s\s\s\s*\sWe\scan't\sfinish\sthe\sbackground\sflush\suntil\swe\srun\sout\sof\sdata\sand\sthe\r\n\s\s\s\s\s*\schannel\sbecomes\swritable\sagain.\sThis\sensures\sthat\sall\sof\sthe\spending\r\n\s\s\s\s\s*\sdata\shas\sbeen\sflushed\sat\sthe\ssystem\slevel.\r\n\s\s\s\s\s*/\r\n\r\n\s\s\s\sif\s(statePtr->flags\s&\sBG_FLUSH_SCHEDULED)\s{\r\n\tif\s(wroteSome)\s{\r\n\t\s\s\s\sreturn\serrorCode;\r\n\t}\selse\sif\s(statePtr->outQueueHead\s==\sNULL)\s{\r\n\t\s\s\s\sResetFlag(statePtr,\sBG_FLUSH_SCHEDULED);\r\n\t\s\s\s\s(chanPtr->typePtr->watchProc)(chanPtr->instanceData,\r\n\t\t\s\s\s\sstatePtr->interestMask);\r\n\t}\r\n\s\s\s\s}\r\n\r\nBecause\sBG_FLUSH_SCHEDULED\sis\sstill\sset,\swhen\sthe\schannel\sis\sclosed,\sTcl_UnregisterChannel\swill\snot\scall\sTcl_Close\s(tcl8.5.15/generic/tclIO.c,\sTcl_UnregisterChannel,\sll.\s1090ff.):\r\n\r\n\s\s\s\s/*\r\n\s\s\s\s\s*\sIf\sthe\srefCount\sreached\szero,\sclose\sthe\sactual\schannel.\r\n\s\s\s\s\s*/\r\n\r\n\s\s\s\sif\s(statePtr->refCount\s<=\s0)\s{\r\n\t/*\r\n\t\s*\sEnsure\sthat\sif\sthere\sis\sanother\sbuffer,\sit\sgets\sflushed\swhether\sor\r\n\t\s*\snot\swe\sare\sdoing\sa\sbackground\sflush.\r\n\t\s*/\r\n\r\n\tif\s((statePtr->curOutPtr\s!=\sNULL)\s&&\r\n\t\tIsBufferReady(statePtr->curOutPtr))\s{\r\n\t\s\s\s\sSetFlag(statePtr,\sBUFFER_READY);\r\n\t}\r\n\tTcl_Preserve((ClientData)statePtr);\r\n\tif\s(!(statePtr->flags\s&\sBG_FLUSH_SCHEDULED))\s{\r\n\t\s\s\s\s/*\r\n\t\s\s\s\s\s*\sWe\sdon't\swant\sto\sre-enter\sTcl_Close().\r\n\t\s\s\s\s\s*/\r\n\r\n\t\s\s\s\sif\s(!(statePtr->flags\s&\sCHANNEL_CLOSED))\s{\r\n\t\tif\s(Tcl_Close(interp,\schan)\s!=\sTCL_OK)\s{\r\n\t\t\s\s\s\sSetFlag(statePtr,\sCHANNEL_CLOSED);\r\n\t\t\s\s\s\sTcl_Release((ClientData)statePtr);\r\n\t\t\s\s\s\sreturn\sTCL_ERROR;\r\n\t\t}\r\n\t\s\s\s\s}\r\n\t}\r\n\tSetFlag(statePtr,\sCHANNEL_CLOSED);\r\n\tTcl_Release((ClientData)statePtr);\r\n\s\s\s\s}\r\n\r\n\r\n\r\nHowever,\sbecause\sof\sthe\snon-standard\sbehaviour\sof\sselect(2)\sdescribed\sabove,\sthe\ssocket-descriptor\swill\snever\sbe\sreturned\sby\sselect(2)\sas\swritable.\s\sConsequently,\sTcl_NotifyChannel\swill\snever\scall\sFlushChannel\sagain,\sand\sso\sFlushChannel\sdoesn't\sclose\sit\seither\s(tcl8.5.15/generic/tclIO.c,\sFlushChannel,\sll.\s2627ff.):\r\n\r\n\s\s\s\s/*\r\n\s\s\s\s\s*\sIf\sthe\schannel\sis\sflagged\sas\sclosed,\sdelete\sit\swhen\sthe\srefCount\sdrops\r\n\s\s\s\s\s*\sto\szero,\sthe\soutput\squeue\sis\sempty\sand\sthere\sis\sno\soutput\sin\sthe\r\n\s\s\s\s\s*\scurrent\soutput\sbuffer.\r\n\s\s\s\s\s*/\r\n\r\n\s\s\s\sif\s((statePtr->flags\s&\sCHANNEL_CLOSED)\s&&\s(statePtr->refCount\s<=\s0)\s&&\r\n\t\s\s\s\s(statePtr->outQueueHead\s==\sNULL)\s&&\r\n\t\s\s\s\s((statePtr->curOutPtr\s==\sNULL)\s||\r\n\t\s\s\s\sIsBufferEmpty(statePtr->curOutPtr)))\s{\r\n\treturn\sCloseChannel(interp,\schanPtr,\serrorCode);\r\n\s\s\s\s}\r\n\r\nChanging\sFlushChannel\sso\sas\salways\sto\sclear\sBG_FLUSH_SCHEDULED\sif\sthe\soutput\sbuffer\sis\sempty\sappears\sto\sfix\sthe\sbug\s(tcl8.5.15/generic/tclIO.c,\sFlushChannel,\sll.\s2610ff.):\r\n\r\n\s\s\s\sif\s(statePtr->flags\s&\sBG_FLUSH_SCHEDULED)\s{\r\n\tif\s(statePtr->outQueueHead\s==\sNULL)\s{\r\n\t\s\s\s\sResetFlag(statePtr,\sBG_FLUSH_SCHEDULED);\r\n\t\s\s\s\s(chanPtr->typePtr->watchProc)(chanPtr->instanceData,\r\n\t\t\s\s\s\sstatePtr->interestMask);\r\n\t}\r\n\tif\s(wroteSome)\s{\r\n\t\s\s\s\sreturn\serrorCode;\r\n\t}\r\n\s\s\s\s}
J foundin 8.5.15,\s8.6.1
J is_private 0
J login a3a3el
J priority 5\sMedium
J private_contact 39e20716815af3b420c05fe7afb33a91d4ea98fc
J resolution None
J severity Important
J status Open
J submitter a3a3el
J subsystem 25.\sChannel\sSystem
J title Flushing\schannels\scan\scaused\sleaked\sfile-descriptors
J type Bug
K 1758a0b6035fcb3425cae757aeba704d67346902
U a3a3el
Z 637ce9ce0e73107a94a1cee800332a81