--------------------- PatchSet 4089 Date: 2007/03/08 22:09:35 Author: rousskov Branch: squid3-icap Tag: (none) Log: - setConsumer is now setConsumerIfNotLate and may fail if the body pipe has auto-consumed data. Handle setConsumerIfNotLate() failures or assert that there must not be any, depending on the context. Members: src/Server.cc:1.4.2.5->1.4.2.6 src/client_side_request.cc:1.34.4.25->1.34.4.26 src/ftp.cc:1.29.2.12->1.29.2.13 src/http.cc:1.49.2.62->1.49.2.63 src/http.h:1.11.4.20->1.11.4.21 src/ICAP/ICAPModXact.cc:1.1.2.23->1.1.2.24 Index: squid3/src/Server.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Server.cc,v retrieving revision 1.4.2.5 retrieving revision 1.4.2.6 diff -u -r1.4.2.5 -r1.4.2.6 --- squid3/src/Server.cc 14 Feb 2007 06:33:46 -0000 1.4.2.5 +++ squid3/src/Server.cc 8 Mar 2007 22:09:35 -0000 1.4.2.6 @@ -1,5 +1,5 @@ /* - * $Id: Server.cc,v 1.4.2.5 2007/02/14 06:33:46 rousskov Exp $ + * $Id: Server.cc,v 1.4.2.6 2007/03/08 22:09:35 rousskov Exp $ * * DEBUG: * AUTHOR: Duane Wessels @@ -392,7 +392,8 @@ if (reply->body_pipe != NULL) { // subscribe to receive adapted body adaptedBodySource = reply->body_pipe; - adaptedBodySource->setConsumer(this); + // assume that ICAP does not auto-consume on failures + assert(adaptedBodySource->setConsumerIfNotLate(this)); } else { // no body handleIcapCompleted(); Index: squid3/src/client_side_request.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/client_side_request.cc,v retrieving revision 1.34.4.25 retrieving revision 1.34.4.26 diff -u -r1.34.4.25 -r1.34.4.26 --- squid3/src/client_side_request.cc 28 Feb 2007 18:15:58 -0000 1.34.4.25 +++ squid3/src/client_side_request.cc 8 Mar 2007 22:09:35 -0000 1.34.4.26 @@ -1,6 +1,6 @@ /* - * $Id: client_side_request.cc,v 1.34.4.25 2007/02/28 18:15:58 rousskov Exp $ + * $Id: client_side_request.cc,v 1.34.4.26 2007/03/08 22:09:35 rousskov Exp $ * * DEBUG: section 85 Client-side Request Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -1127,7 +1127,7 @@ // subscribe to receive reply body if (new_rep->body_pipe != NULL) { icapBodySource = new_rep->body_pipe; - icapBodySource->setConsumer(this); + assert(icapBodySource->setConsumerIfNotLate(this)); } clientStreamNode *node = (clientStreamNode *)client_stream.tail->prev->data; Index: squid3/src/ftp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ftp.cc,v retrieving revision 1.29.2.12 retrieving revision 1.29.2.13 diff -u -r1.29.2.12 -r1.29.2.13 --- squid3/src/ftp.cc 14 Feb 2007 06:33:45 -0000 1.29.2.12 +++ squid3/src/ftp.cc 8 Mar 2007 22:09:35 -0000 1.29.2.13 @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.29.2.12 2007/02/14 06:33:45 rousskov Exp $ + * $Id: ftp.cc,v 1.29.2.13 2007/03/08 22:09:35 rousskov Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -2576,6 +2576,14 @@ debug(9, 3) ("This is ftpReadStor\n"); if (code == 125 || (code == 150 && data.host)) { + // register to receive body data + assert(request->body_pipe != NULL); + if (!request->body_pipe->setConsumerIfNotLate(this)) { + debug(9, 3) ("ftpReadStor: aborting on partially consumed body\n"); + ftpFail(this); + return; + } + /* Begin data transfer */ debug(9, 3) ("ftpReadStor: starting data transfer\n"); sendMoreRequestBody(); @@ -2587,10 +2595,6 @@ commSetTimeout(data.fd, Config.Timeout.read, FtpStateData::ftpTimeout, this); - // register to receive body data - assert(request->body_pipe != NULL); - request->body_pipe->setConsumer(this); - state = WRITING_DATA; debug(9, 3) ("ftpReadStor: writing data channel\n"); } else if (code == 150) { Index: squid3/src/http.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/http.cc,v retrieving revision 1.49.2.62 retrieving revision 1.49.2.63 diff -u -r1.49.2.62 -r1.49.2.63 --- squid3/src/http.cc 28 Feb 2007 18:16:00 -0000 1.49.2.62 +++ squid3/src/http.cc 8 Mar 2007 22:09:35 -0000 1.49.2.63 @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.49.2.62 2007/02/28 18:16:00 rousskov Exp $ + * $Id: http.cc,v 1.49.2.63 2007/03/08 22:09:35 rousskov Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -1719,7 +1719,7 @@ } /* This will be called when connect completes. Write request. */ -void +bool HttpStateData::sendRequest() { MemBuf mb; @@ -1732,7 +1732,11 @@ if (orig_request->body_pipe != NULL) { requestBodySource = orig_request->body_pipe; - requestBodySource->setConsumer(this); + if (!requestBodySource->setConsumerIfNotLate(this)) { + debugs(32,3, HERE << "aborting on partially consumed body"); + requestBodySource = NULL; + return false; + } requestSender = HttpStateData::sentRequestBodyWrapper; debugs(32,3, HERE << "expecting request body on pipe " << requestBodySource); } else { @@ -1778,6 +1782,8 @@ buildRequestPrefix(request, orig_request, entry, &mb, flags); debug(11, 6) ("httpSendRequest: FD %d:\n%s\n", fd, mb.buf); comm_write_mbuf(fd, &mb, requestSender, this); + + return true; } void @@ -1788,12 +1794,15 @@ storeUrl(fwd->entry)); HttpStateData *httpState = new HttpStateData(fwd); - statCounter.server.all.requests++; + if (!httpState->sendRequest()) { + debug(11, 3) ("httpStart: aborted"); + delete httpState; + return; + } + statCounter.server.all.requests++; statCounter.server.http.requests++; - httpState->sendRequest(); - /* * We used to set the read timeout here, but not any more. * Now its set in httpSendComplete() after the full request, Index: squid3/src/http.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/http.h,v retrieving revision 1.11.4.20 retrieving revision 1.11.4.21 diff -u -r1.11.4.20 -r1.11.4.21 --- squid3/src/http.h 14 Feb 2007 06:33:45 -0000 1.11.4.20 +++ squid3/src/http.h 8 Mar 2007 22:09:38 -0000 1.11.4.21 @@ -1,6 +1,6 @@ /* - * $Id: http.h,v 1.11.4.20 2007/02/14 06:33:45 rousskov Exp $ + * $Id: http.h,v 1.11.4.21 2007/03/08 22:09:38 rousskov Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -62,7 +62,7 @@ virtual int dataDescriptor() const; /* should be private */ - void sendRequest(); + bool sendRequest(); void processReplyHeader(); void processReplyBody(); void readReply(size_t len, comm_err_t flag, int xerrno); Index: squid3/src/ICAP/ICAPModXact.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/ICAPModXact.cc,v retrieving revision 1.1.2.23 retrieving revision 1.1.2.24 diff -u -r1.1.2.23 -r1.1.2.24 --- squid3/src/ICAP/ICAPModXact.cc 8 Mar 2007 05:24:22 -0000 1.1.2.23 +++ squid3/src/ICAP/ICAPModXact.cc 8 Mar 2007 22:09:38 -0000 1.1.2.24 @@ -1236,7 +1236,7 @@ // sign up as a body consumer Must(msg->body_pipe != NULL); Must(msg->body_pipe == virgin.body_pipe); - virgin.body_pipe->setConsumer(this); + Must(virgin.body_pipe->setConsumerIfNotLate(this)); // make sure TheBackupLimit is in-sync with the buffer size Must(TheBackupLimit <= static_cast(msg->body_pipe->buf().max_capacity));