From: Alex Rousskov Date: Sun, 9 Mar 2014 01:48:00 +0000 (-0700) Subject: Avoid assertions on Range requests that trigger Squid-generated errors. X-Git-Tag: SQUID_3_4_4~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f7d508bc54e14ecec6e51fc5654408ec3b312ad;p=thirdparty%2Fsquid.git Avoid assertions on Range requests that trigger Squid-generated errors. Added HttpRequest::ignoreRange() to encapsulate range ignoring logic. Currently the new method only contains the code common among all callers. More work is needed to check whether further caller homogenization is possible. Documented that ClientSocketContext::getNextRangeOffset() may sometimes be called before it is ready to do its job. --- diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index ce6c411d0b..d43b23df46 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -666,6 +666,20 @@ HttpRequest::getRangeOffsetLimit() return rangeOffsetLimit; } +void +HttpRequest::ignoreRange(const char *reason) +{ + if (range) { + debugs(73, 3, static_cast(range) << " for " << reason); + delete range; + range = NULL; + } + // Some callers also reset isRanged but it may not be safe for all callers: + // isRanged is used to determine whether a weak ETag comparison is allowed, + // and that check should not ignore the Range header if it was present. + // TODO: Some callers also delete HDR_RANGE, HDR_REQUEST_RANGE. Should we? +} + bool HttpRequest::canHandle1xx() const { diff --git a/src/HttpRequest.h b/src/HttpRequest.h index b1301fa706..65dbf5efd1 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -262,6 +262,8 @@ public: */ CbcPointer clientConnectionManager; + /// forgets about the cached Range header (for a reason) + void ignoreRange(const char *reason); int64_t getRangeOffsetLimit(); /* the result of this function gets cached in rangeOffsetLimit */ private: diff --git a/src/client_side.cc b/src/client_side.cc index 3d9614df08..817ec4623d 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1366,9 +1366,7 @@ ClientSocketContext::buildRangeHeader(HttpReply * rep) * offset data, but we won't be requesting it. * So, we can either re-request, or generate an error */ - debugs(33, 3, "clientBuildRangeHeader: will not do ranges: " << range_err << "."); - delete http->request->range; - http->request->range = NULL; + http->request->ignoreRange(range_err); } else { /* XXX: TODO: Review, this unconditional set may be wrong. */ rep->sline.set(rep->sline.version, Http::scPartialContent); @@ -1747,9 +1745,16 @@ ClientSocketContext::canPackMoreRanges() const int64_t ClientSocketContext::getNextRangeOffset() const { + debugs (33, 5, "range: " << http->request->range << + "; http offset " << http->out.offset << + "; reply " << reply); + + // XXX: This method is called from many places, including pullData() which + // may be called before prepareReply() [on some Squid-generated errors]. + // Hence, we may not even know yet whether we should honor/do ranges. + if (http->request->range) { /* offset in range specs does not count the prefix of an http msg */ - debugs (33, 5, "ClientSocketContext::getNextRangeOffset: http offset " << http->out.offset); /* check: reply was parsed and range iterator was initialized */ assert(http->range_iter.valid); /* filter out data according to range specs */ @@ -1786,7 +1791,7 @@ ClientSocketContext::getNextRangeOffset() const void ClientSocketContext::pullData() { - debugs(33, 5, HERE << clientConnection << " attempting to pull upstream data"); + debugs(33, 5, reply << " written " << http->out.size << " into " << clientConnection); /* More data will be coming from the stream. */ StoreIOBuffer readBuffer; @@ -2578,7 +2583,7 @@ bool ConnStateData::serveDelayedError(ClientSocketContext *context) clientReplyContext *repContext = dynamic_cast(node->data.getRaw()); assert(repContext); debugs(33, 5, "Responding with delated error for " << http->uri); - repContext->setReplyToStoreEntry(sslServerBump->entry); + repContext->setReplyToStoreEntry(sslServerBump->entry, "delayed SslBump error"); // save the original request for logging purposes if (!context->http->al->request) { diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index d38d3820a5..01da7dc5d8 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -132,13 +132,18 @@ void clientReplyContext::setReplyToError(const HttpRequestMethod& method, ErrorS http->al->http.code = errstate->httpStatus; + if (http->request) + http->request->ignoreRange("responding with a Squid-generated error"); + createStoreEntry(method, RequestFlags()); assert(errstate->callback_data == NULL); errorAppendEntry(http->storeEntry(), errstate); /* Now the caller reads to get this */ } -void clientReplyContext::setReplyToStoreEntry(StoreEntry *entry) +// Assumes that the entry contains an error response without Content-Range. +// To use with regular entries, make HTTP Range header removal conditional. +void clientReplyContext::setReplyToStoreEntry(StoreEntry *entry, const char *reason) { entry->lock(); // removeClientStoreReference() unlocks sc = storeClientListAdd(entry, this); @@ -147,6 +152,8 @@ void clientReplyContext::setReplyToStoreEntry(StoreEntry *entry) #endif reqofs = 0; reqsize = 0; + if (http->request) + http->request->ignoreRange(reason); flags.storelogiccomplete = 1; http->storeEntry(entry); } diff --git a/src/client_side_reply.h b/src/client_side_reply.h index 15a34fe0de..7b294ab6bb 100644 --- a/src/client_side_reply.h +++ b/src/client_side_reply.h @@ -68,7 +68,7 @@ public: int storeOKTransferDone() const; int storeNotOKTransferDone() const; /// replaces current response store entry with the given one - void setReplyToStoreEntry(StoreEntry *e); + void setReplyToStoreEntry(StoreEntry *e, const char *reason); /// builds error using clientBuildError() and calls setReplyToError() below void setReplyToError(err_type, Http::StatusCode, const HttpRequestMethod&, char const *, Ip::Address &, HttpRequest *, const char *, #if USE_AUTH diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 073af4f964..8e9368f9b5 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -1145,8 +1145,7 @@ clientInterpretRequestHeaders(ClientHttpRequest * http) else { req_hdr->delById(HDR_RANGE); req_hdr->delById(HDR_REQUEST_RANGE); - delete request->range; - request->range = NULL; + request->ignoreRange("neither HEAD nor GET"); } if (req_hdr->has(HDR_AUTHORIZATION)) @@ -1813,7 +1812,7 @@ ClientHttpRequest::doCallouts() clientStreamNode *node = (clientStreamNode *)client_stream.tail->prev->data; clientReplyContext *repContext = dynamic_cast(node->data.getRaw()); assert (repContext); - repContext->setReplyToStoreEntry(e); + repContext->setReplyToStoreEntry(e, "immediate SslBump error"); errorAppendEntry(e, calloutContext->error); calloutContext->error = NULL; if (calloutContext->readNextRequest) diff --git a/src/http.cc b/src/http.cc index 4003219814..e3ae204c1d 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1725,8 +1725,7 @@ HttpStateData::httpBuildRequestHeader(HttpRequest * request, /* don't cache the result */ request->flags.cachable = false; /* pretend it's not a range request */ - delete request->range; - request->range = NULL; + request->ignoreRange("want to request the whole object"); request->flags.isRanged = false; }