Skip to content
Tcl Source Code Artifact [1de540d019]
Login

Artifact [1de540d019]

Artifact 1de540d019a67427fe1ca9a39659c1c9566591eee08ce35e7728567077c00d0d:

Ticket change [1de540d019] - Ticket [46b6edad51e645c7|46b6edad51] <i>HTTP Keep-Alive with Pipelined requests fails</i> status still Open with 3 other changes by kjnash on 2018-04-01 14:27:46.
D 2018-04-01T14:27:46.109
J icomment Tcl\sbranch\sbug-46b6edad51-concurrent-http\sfixes\sthis\sproblem.\r\n\r\nI.\sQUEUEING\sAND\sPIPELINING\sREQUESTS\r\n\r\nThe\sexisting\shttp\slibrary\sdoes\snot\shandle\sconcurrent\suse\sof\sa\spersistent\r\nconnection\scorrectly:\sit\smakes\sit\sthe\sresponsibility\sof\sthe\scaller\sof\r\nhttp::geturl\sto\scheck\sthat\sone\sHTTP\stransaction\sis\scomplete\sbefore\ssubmitting\r\nthe\snext.\s\sAlso,\sit\sdoes\snot\smonitor\sidle\sconnections\sfor\sclosure\sat\sthe\r\nserver\send.\r\n\r\nThe\srevisions\sin\sbranch\sbug-46b6edad51-concurrent-http\sarrange\sfor\ssuch\sHTTP\r\nrequests\sto\sbe\squeued\suntil\sthe\sconnection\sis\savailable,\sand\spipelined\sif\r\nappropriate.\s\sIf\sthe\sconnection\sis\slost,\sRFC\s7230\spermits\sretry\sin\ssome\scases.\r\nConnections\sare\smonitored\sfor\sserver\stimeout.\r\n\r\nNew\soptions\sfor\shttp::config\scontrol\sthese\sfacilities:\r\n\r\n-pipeline\sboolean\r\n\s\s\s\sSpecifies\swhether\sHTTP/1.1\stransactions\son\sa\spersistent\ssocket\swill\sbe\r\n\s\s\s\spipelined.\sThe\sdefault\sis\s1.\r\n-postfresh\sboolean\r\n\s\s\s\sSpecifies\s\swhether\srequests\sthat\suse\sthe\sPOST\smethod\swill\salways\suse\sa\r\n\s\s\s\sfresh\ssocket,\soverriding\sthe\s-keepalive\soption\sof\scommand\shttp::geturl.\r\n\s\s\s\sThe\sdefault\sis\s0.\r\n-repost\sboolean\r\n\s\s\s\sSpecifies\swhat\sto\sdo\sif\sa\sPOST\srequest\sover\sa\spersistent\sconnection\sfails\r\n\s\s\s\sbecause\sthe\sserver\shas\shalf-closed\sthe\sconnection.\s\sIf\sboolean\strue,\sthe\r\n\s\s\s\srequest\swill\sbe\sautomatically\s\sretried;\sif\sboolean\sfalse\sit\swill\snot,\sand\r\n\s\s\s\sthe\sapplication\sthat\suses\shttp::geturl\sis\sexpected\sto\sseek\suser\sconfirmation\r\n\s\s\s\sbefore\sretrying\sthe\sPOST.\sThe\sdefault\sis\s0.\r\n\r\nFurther\sdiscussion\sin\ssection\s"PERSISTENT\sCONNECTIONS"\sof\shttp(n).\r\n\r\nII.\sFIXING\sSTALLED\sHTTPS\sTRANSFERS\r\n\r\nTcltls\sbug\shttps://core.tcl.tk/tcltls/tktview/94c6a431fe\r\n\r\nA\shttps\srequest\sfor\san\sentity\sthat\sis\slarger\sthan\sthe\shttp::geturl\soption\r\n-blocksize\shangs\sif\sthe\sserver\sresponse\suses\sa\spersistent\sconnection\sand\r\ndoes\snot\suse\schunked\sencoding\s(but\sdoes\ssupply\san\saccurate\sContent-Length\r\nheader).\s\sThe\sclient\sdoes\snot\sfinish\sreading\suntil\sthe\sserver\stimes\sout.\r\nI\sam\snot\ssure\swhether\sthis\sbug\slies\sin\sTcltls,\sTcl\sstacked\schannels,\sthe\r\nTcl\s[read]\scommand,\sfileevent\sgeneration\sor\sbuffering,\sbut\sI\shave\ssubmitted\r\na\sticket\son\sTcltls.\r\n\r\nThe\sbug\sis\sworked\saround\sby\sspecifying\sthe\snumber\sof\scharacters\sfor\seach\r\n[read]\sas\s($state(totalsize)\s-\s$state(currentsize)).\r\n\r\nIt\sappears\sto\sbe\snecessary\sto\sdo\sthis\sfor\severy\sread,\snot\sonly\sfor\sthe\slast\r\nread(s)\swhere\sthis\squantity\sis\ssmaller\sthan\sthe\s-blocksize\sthat\swould\snormally\r\nbe\srequested.\r\n\r\nIII.\sDON'T\sASSUME\sTHE\sSERVER\sWILL\sDEFAULT\sTO\sKEEP-ALIVE\r\n\r\nThis\sbehavior\sis\smandatory\sin\sRFC\s7230,\sbut\sNOT\sin\sthe\ssuperseded\sRFC\s2616.\r\nMuch\sof\sthe\sweb\sis\sdelivered\sby\sservers\sthat\scomply\swith\sthe\solder\sstandard.\r\nThese\smay\sclose\sthe\sconnection\sif\sthe\sclient\sdoes\snot\ssend\sa\r\n"Connection:\skeep-alive"\sheader.\s\sThe\shttp\spackage\ssends\sthe\sheader\sonly\sfor\r\nHTTP/1.0.\s\sThe\snew\sbranch\sfixes\sthis\sbug\sand\ssends\sthe\sheader\sfor\sHTTP/1.1\salso.\r\n\r\nIV.\sDISABLING\sCOMPRESSION\r\n\r\nBy\sdefault\shttp\sasks\sthe\sserver\sto\scompress\sthe\sHTTP\sresponse.\s\sA\snew\soption\sfor\r\nhttp::config\sallows\sthis\srequest\sto\sbe\sswitched\soff.\r\n\r\n-zip\sboolean\r\n\s\s\s\sIf\sthe\svalue\sis\sboolean\strue,\sthen\sby\sdefault\srequests\swill\ssend\sa\sheader\r\n\s\s\s\s"Accept-Encoding:\sgzip,deflate,compress".\s\sIf\sthe\svalue\sis\sboolean\sfalse,\r\n\s\s\s\sthen\sby\sdefault\s\sthis\sheader\swill\snot\sbe\ssent.\s\sIn\seither\scase\sthe\sdefault\r\n\s\s\s\scan\sbe\soverridden\sfor\san\sindividual\srequest\sby\ssupplying\sa\scustom\r\n\s\s\s\sAccept-Encoding\sheader\sin\sthe\s-headers\soption\sof\shttp::geturl.\sThe\sdefault\r\n\s\s\s\sis\s1.\r\n\r\nV.\sMODIFIED\sFILES\s(cf.\s8.6.8)\r\n\r\nEDITED\s\s\s\s\sdoc/http.n\r\nEDITED\s\s\s\s\slibrary/http/http.tcl\r\nEDITED\s\s\s\s\stests/http11.test\r\nADDED\s\s\s\s\s\stests/httpPipeline.test\r\nADDED\s\s\s\s\s\stests/httpTest.tcl\r\nADDED\s\s\s\s\s\stests/httpTestScript.tcl\r\n\r\nVI.\sTESTS\r\n\r\nThe\stests\sin\sthe\snew\stest\sfile\stests/httpPipeline.test\sall\shave\sa\sconstraint\r\n"serverNeeded"\sand\sso\sby\sdefault\sare\snot\sexecuted.\r\n\r\nThere\sare\sover\s1000\stests,\swhich\sare\stime-consuming\sbecause\sthey\suse\sa\sdelay\r\nto\sensure\sthat\spersistent\sconnections\sto\sthe\sserver\shave\stimed\sout,\sand\sthey\r\nalso\ssuffer\sfrom\snetwork\slatency.\s\sSome\stests\smay\sappear\ssuperfluous,\sbut\sthey\r\ndo\sreveal\sbugs,\sincluding\ssome\swhere\stest\sfailure\sdepends\son\sthe\sdetails\sof\r\nclient/server\stiming\sand\sis\stherefore\sintermittent.\r\n\r\nVII.\sDETAILS\sOF\sCOMMIT\s680b022c38\r\n\r\nRefactor\svariable\snames:\r\n\s\s\s\sconn_id\s->\sconnId\s(in\s::http::CloseSocket)\r\n\s\s\s\ssocketmap\s->\ssocketMapping\s(namespace\svariable)\r\n\s\s\s\sIn\shttp::Event,\slocal\svariable\s"n"\sis\sused\sfor\smultiple\spurposes.\r\n\s\s\s\sReserve\sit\sfor\san\sincrement\sto\sthe\slength\sof\sthe\sresponse\sbody,\sand\sapply\r\n\s\s\s\sn\s->\snsl,\snhl,\sntl\sfor\sits\sother\smeanings.\sSet\sn\s0\sin\sone\splace.\r\n\s\s\s\sIn\shttp::Event,\slocal\svariable\s"chunk"\sis\sused\sfor\stwo\spurposes.\r\n\s\s\s\schunk\s->\shexLenChunk\swhen\sit\sholds\sthe\slength\sof\sthe\schunk\sin\r\n\s\s\s\shexadecimal.\r\n\r\nRefactor\scommand\sname:\r\n\s\s\s\sEof\s->\sEot\s(the\scommand\sis\ssometimes\scalled\swhen\snot\seof.\s\sComments\sin\r\n\s\s\s\scommand\sheader\supdated.)\r\n\r\nVIII.\sDETAILS\sOF\sCOMMIT\s78b23edb6b\r\n\r\n\s\s\s\s\s\sa.\sCarefully\sdistinguish\sexpected\sand\spremature\seof.\r\n\s\s\s\s\s\s\s\s\sIn\shttp::Eot\s--\r\n\s\s\s\s\s\s\s\s\s-\sRemove\soptional\sargument\s"force"\swhich\sis\snever\sused.\r\n\s\s\s\s\s\s\s\s\s-\sDo\snot\suse\s($state(state)\seq\s"header")\sto\stest\swhether\sthe\r\n\s\s\s\s\s\s\s\s\s\s\stransaction\sis\scomplete.\s\sRely\son\sa\snew\sargument\s"reason"\sinstead.\r\n\s\s\s\s\s\s\s\s\s-\sPass\smodified\svalue\s$reason\sto\shttp::Finish.\r\n\s\s\s\s\s\s\s\s\sIn\shttp::Finish\s--\r\n\s\s\s\s\s\s\s\s\s-\sCall\sCloseSocket\sif\sstate(status)\sis\s"eof".\r\n\s\s\s\s\s\s\s\s\sIn\shttp::Entry\s--\r\n\s\s\s\s\s\s\s\s\s-\sSet\sstate(state)\sto\snew\svalue\s"complete"\sto\ssignal\sthat\sthe\sresponse\r\n\s\s\s\s\s\s\s\s\s\s\sis\scomplete,\sor\swill\sbe\scomplete\swhen\sthe\sserver\scloses\sthe\r\n\s\s\s\s\s\s\s\s\s\s\sconnection.\s\sThe\svalue\sis\sread\swithin\shttp::Entry\s(and\snowhere\selse)\r\n\s\s\s\s\s\s\s\s\s\s\sas\sa\stest\sof\scompletion.\r\n\s\s\s\s\s\sb.\sBugfixes\sin\srecording\sthe\ssize\sof\sthe\sresponse\sbody.\r\n\s\s\s\s\s\s\s\s\sIn\shttp::Entry\s--\r\n\s\s\s\s\s\s\s\s\s-\sDo\snot\scount\s$n\stowards\sthe\ssize\sof\sthe\sbody\sif\sit\sis\snot\r\n\s\s\s\s\s\s\s\s\s\s\sthe\slength\sof\sa\spart\sof\sthe\sbody.\s\sSet\sit\sto\s0\sinstead.\r\n\s\s\s\s\s\s\s\s\s\s\sThis\sincludes\sHTTP\strailers.\r\n\s\s\s\s\s\sc.\sTerminate\sthe\sresponse\sand\sthe\sconnection\sif\sthere\sis\san\serror\swith\r\n\s\s\s\s\s\s\s\s\schunked\sencoding.\r\n\s\s\s\s\s\sd.\sWhen\susing\s-handler\soption\sto\shttp::geturl,\sterminate\sthe\sresponse\sif\r\n\s\s\s\s\s\s\s\s\sthe\shandler\scommand\sdoes\snot\sreturn\san\sinteger\sresult\sas\srequired\s(and\r\n\s\s\s\s\s\s\s\s\sdocumented).\r\n\s\s\s\s\s\s\s\s\s-\sThis\schange\scan\sbe\sreversed\sif\sconsidered\sinappropriate,\sbut\sat\sthe\r\n\s\s\s\s\s\s\s\s\s\s\scost\sof\s(a)\snot\sknowing\sthe\ssize\sof\sthe\sresponse\sbody,\s(b)\shaving\sto\r\n\s\s\s\s\s\s\s\s\s\s\suse\sserver\seof\sto\sdefine\sthe\send\sof\sthe\sresource,\sand\r\n\s\s\s\s\s\s\s\s\s\s\s(c)\sincompatibility\swith\skeep-alive.\r\n\s\s\s\s\s\se.\sAdd\ssome\scommented-out\s"##Log"\scalls\sfor\sdebugging.\r\n\s\s\s\s\s\sf.\sDefine\snew\svariable\sstate(log_size)\spurely\sfor\slogging\sthe\scumulative\r\n\s\s\s\s\s\s\s\s\ssize\sof\sthe\sresponse\sbody.\r\n\r\nAnd\scf.\scommit\s60eee5809f:\r\n\s\s\s\s\s\sa.\sAmend\sthe\scommand\s"handler"\sin\stests/http11.test,\sto\sreturn\san\sinteger\r\n\s\s\s\s\s\s\s\s\sas\srequired\sby\shttp(n),\sand\salso\snot\sto\scheck\sfor\seof\swhich\sis\sthe\r\n\s\s\s\s\s\s\s\s\sresponsibility\sof\shttp.\sThis\sform\sof\sthe\stest\sis\sappropriate\sfor\scommits\sfrom\s78b23edb6b\sonwards.\r\n\r\nIX.\sDETAILS\sOF\sCOMMIT\s8ac0b6f067\r\n\r\nBugfixes\sfor\soccasional\stest\sfailures,\sand\simprovements\sfor\s(possibly\shypothetical)\scases.\r\n\r\nlibrary/http/http.tcl\r\n1.\sModify\shttp::init\sto\suse\sCloseSocket\sand\sclear\sold\spersistent-connection\sdata\sgracefully.\r\n2.\sUnset\sstate(after)\swhen\sits\sevent\sis\scancelled.\r\n3.\sWhen\sthe\sserver\ssends\s"Connection:\sclose",\sdo\snot\sclear\sthe\squeues\sin\shttp::Event\sbecause\sthey\sare\sneeded\sif\shttp::Finish\sis\scalled\swith\serror\sstatus.\s\sInstead\sclear\sthem\sin\shttp::CloseQueuedQueries;\salso\s(in\sseveral\splaces)\suse\ssocketPlayCmd(*),\ssocketClosing(*)\sinstead\sof\sempty\squeues\sto\ssignal\sthat\sthe\ssocket\swill\sclose.\r\n4.\sSplit\shttp::Unset\sfrom\shttp::CloseQueuedQueries\sand\shttp::geturl.\r\n5.\sIn\shttp::geturl\sand\shttp::ReplayCore,\sinitialize\sall\ssocket*($state(socketinfo))\sarray\selements.\s\sTest\sexistence\sof\sthe\scorrect\svariables\sbefore\ssetting\straces.\s\sReorder\scode\sso\sthe\snew\stests\soccur\sbefore\ssetting\sthe\svariables.\r\n6.\sRe-sync\shttp::geturl\sand\shttp::ReplayCore.\s\sIf\ssocket\scannot\sbe\sopened,\spass\serror\smessage\sto\shttp::Finish\sand\sset\sstate(sock)\sNONE.\s\sInitialise\ssocketPlayCmd(*)\sto\ssame\svalue.\r\n7.\sAdd\sLog\scalls\sto\sreport\scode\sthat\sappears\sto\sbe\srarely\sexecuted.\r\n8.\sImprove\sLog\smessages\sin\shttp::CancelReadPipeline\shttp::CancelWritePipeline\r\n9.\sDo\snot\suse\s"unset\ssocketRdState(*)"\sas\sa\s"hard\scancel"\sfor\squeued\stokens\sin\shttp::ReplayIfDead;\sinstead\sa\s"soft\scancel"\sis\sprovided\sin\shttp::ReplayCore\sand\shttp::ReInit,\sthat\sdoes\snot\sset\sthe\sstate\sto\sindicate\sfailure.\sThe\sstate(after)\sevent\sis\snow\scancelled\sin\shttp::ReInit\snot\shttp::ReplayIfDead.\r\n10.\sSplit\shttp::ReInit\sfrom\shttp::ReplayCore,\sand\salso\sapply\sit\sto\squeued\stokens\sso\sthey\sare\sre-initialized\scorrectly.\r\n11.\sDo\snot\suse\sargument\sskipCB\swhen\scalling\sFinish\sfrom\sReplayCore\s-\sthis\swas\scopied\sin\serror\sfrom\shttp::geturl.\r\n\r\ntests/httpPipeline.test\r\nRename\stests\sto\sdistinguish\sthem\sfrom\stests\sin\sother\sfiles.
J login kjnash
J mimetype text/plain
K 46b6edad51e645c70e88dd4f944a2d4afc63a96a
U kjnash
Z d8bbbece9d154e26a02248ffa17c7464