Compare commits

...

5 Commits

Author SHA1 Message Date
Jeffrey Crowell de82e87246 reapply: location-header: tweak location header handling
- Fix potentially sending the location header into PSOL twice.
- Be more thorough when unsetting the location header

Attempts to fix #725

from oschaaf
2016-01-26 09:44:29 -05:00
Otto van der Schaaf 749511c5c3 Fix valgrind complaint caused by NgxBaseFetch
We should not use r->connection after we finalize the request.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1100
2016-01-26 09:44:21 -05:00
Otto van der Schaaf a7d2e0608c Eliminate CHECK that fails (rarely) during the IPRO lookup.
Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1096
2016-01-26 09:44:14 -05:00
Otto van der Schaaf 07630f6c4a Fix crasher on 404 .pagespeed. resources w/a custom location
- Fix nginx-side flow so we handle .pagespeed. resources ok
  when they will land on a customized 404 internal location.
- Additionally, check for a wiped request context and make sure
  we do not dereference a null pointer, which is what hurt in
  the flow we entered above as the IPRO lookup still was
  generating events while the nginx side request context was
  gone.
- Also, as a preliminary measure, do not check fail when we
  receive a stale event originating from a NgxBaseFetch that
  is no longer associated with our request context.
  Do log a warning so we'll hear about this happening either
  through system test failures or a bug report.

Fixes https://github.com/pagespeed/ngx_pagespeed/issues/1081
2016-01-26 09:44:04 -05:00
Jeff Kaufman d2d1df66cb 1.10.33.2 -> 1.10.33.3 2016-01-26 09:43:47 -05:00
5 changed files with 57 additions and 13 deletions
+2 -2
View File
@@ -29,8 +29,8 @@ if [ "$mod_pagespeed_dir" = "unset" ] ; then
echo " You need to separately download the pagespeed library:" echo " You need to separately download the pagespeed library:"
echo "" echo ""
echo " $ cd /path/to/ngx_pagespeed" echo " $ cd /path/to/ngx_pagespeed"
echo " $ wget https://dl.google.com/dl/page-speed/psol/1.10.33.2.tar.gz" echo " $ wget https://dl.google.com/dl/page-speed/psol/1.10.33.3.tar.gz"
echo " $ tar -xzvf 1.10.33.2.tar.gz # expands to psol/" echo " $ tar -xzvf 1.10.33.3.tar.gz # expands to psol/"
echo "" echo ""
echo " Or see the installation instructions:" echo " Or see the installation instructions:"
echo " https://github.com/pagespeed/ngx_pagespeed#how-to-build" echo " https://github.com/pagespeed/ngx_pagespeed#how-to-build"
+31 -5
View File
@@ -118,6 +118,8 @@ const char* BaseFetchTypeToCStr(NgxBaseFetchType type) {
return "can't get here"; return "can't get here";
} }
// TODO(oschaaf): replace the ngx_log_error with VLOGS or pass in a
// MessageHandler and use that.
void NgxBaseFetch::ReadCallback(const ps_event_data& data) { void NgxBaseFetch::ReadCallback(const ps_event_data& data) {
NgxBaseFetch* base_fetch = reinterpret_cast<NgxBaseFetch*>(data.sender); NgxBaseFetch* base_fetch = reinterpret_cast<NgxBaseFetch*>(data.sender);
ngx_http_request_t* r = base_fetch->request(); ngx_http_request_t* r = base_fetch->request();
@@ -138,19 +140,40 @@ void NgxBaseFetch::ReadCallback(const ps_event_data& data) {
if (refcount == 0 || detached) { if (refcount == 0 || detached) {
return; return;
} }
ps_request_ctx_t* ctx = ps_get_request_context(r); ps_request_ctx_t* ctx = ps_get_request_context(r);
CHECK(data.sender == ctx->base_fetch); // If our request context was zeroed, skip this event.
CHECK(r->count > 0) << "r->count: " << r->count; // See https://github.com/pagespeed/ngx_pagespeed/issues/1081
if (ctx == NULL) {
// Should not happen normally, when it does this message will cause our
// system tests to fail.
ngx_log_error(NGX_LOG_WARN, ngx_cycle->log, 0,
"pagespeed [%p] skipping event: request context gone", r);
return;
}
// Normally we expect the sender to equal the active NgxBaseFetch instance.
DCHECK(data.sender == ctx->base_fetch);
// If someone changed our request context or NgxBaseFetch, skip processing.
if (data.sender != ctx->base_fetch) {
ngx_log_error(NGX_LOG_WARN, ngx_cycle->log, 0,
"pagespeed [%p] skipping event: event originating from disassociated"
" NgxBaseFetch instance.", r);
return;
}
int rc; int rc;
bool run_posted = true;
// If we are unlucky enough to have our connection finalized mid-ipro-lookup, // If we are unlucky enough to have our connection finalized mid-ipro-lookup,
// we must enter a different flow. Also see ps_in_place_check_header_filter(). // we must enter a different flow. Also see ps_in_place_check_header_filter().
if ((ctx->base_fetch->base_fetch_type_ != kIproLookup) if ((ctx->base_fetch->base_fetch_type_ != kIproLookup)
&& r->connection->error) { && r->connection->error) {
ngx_log_error(NGX_LOG_DEBUG, ngx_cycle->log, 0, ngx_log_error(NGX_LOG_DEBUG, ngx_cycle->log, 0,
"pagespeed [%p] request already finalized", r); "pagespeed [%p] request already finalized %d", r, r->count);
rc = NGX_ERROR; rc = NGX_ERROR;
run_posted = false;
} else { } else {
rc = ps_base_fetch::ps_base_fetch_handler(r); rc = ps_base_fetch::ps_base_fetch_handler(r);
} }
@@ -163,8 +186,11 @@ void NgxBaseFetch::ReadCallback(const ps_event_data& data) {
ngx_connection_t* c = r->connection; ngx_connection_t* c = r->connection;
ngx_http_finalize_request(r, rc); ngx_http_finalize_request(r, rc);
// See http://forum.nginx.org/read.php?2,253006,253061
ngx_http_run_posted_requests(c); if (run_posted) {
// See http://forum.nginx.org/read.php?2,253006,253061
ngx_http_run_posted_requests(c);
}
} }
void NgxBaseFetch::Lock() { void NgxBaseFetch::Lock() {
+8 -6
View File
@@ -284,7 +284,8 @@ ngx_int_t ps_base_fetch_handler(ngx_http_request_t* r) {
// modules running after us to manipulate those responses. // modules running after us to manipulate those responses.
if (!status_ok && (ctx->base_fetch->base_fetch_type() != kHtmlTransform if (!status_ok && (ctx->base_fetch->base_fetch_type() != kHtmlTransform
&& ctx->base_fetch->base_fetch_type() != kIproLookup)) { && ctx->base_fetch->base_fetch_type() != kIproLookup)) {
return status_code; ps_release_base_fetch(ctx);
return ngx_http_filter_finalize_request(r, NULL, status_code);
} }
if (ctx->preserve_caching_headers != kDontPreserveHeaders) { if (ctx->preserve_caching_headers != kDontPreserveHeaders) {
@@ -302,6 +303,12 @@ ngx_int_t ps_base_fetch_handler(ngx_http_request_t* r) {
STR_CASE_EQ_LITERAL(header->key, "Last-Modified") || STR_CASE_EQ_LITERAL(header->key, "Last-Modified") ||
STR_CASE_EQ_LITERAL(header->key, "Expires"))))) { STR_CASE_EQ_LITERAL(header->key, "Expires"))))) {
header->hash = 0; header->hash = 0;
if (STR_CASE_EQ_LITERAL(header->key, "Location")) {
// There's a possible issue with the location header, where setting
// the hash to 0 is not enough. See:
// https://github.com/nginx/nginx/blob/master/src/http/ngx_http_header_filter_module.c#L314
r->headers_out.location = NULL;
}
} }
} }
} else { } else {
@@ -452,11 +459,6 @@ void copy_response_headers_from_ngx(const ngx_http_request_t* r,
headers->set_status_code(r->headers_out.status); headers->set_status_code(r->headers_out.status);
if (r->headers_out.location != NULL) {
headers->Add(HttpAttributes::kLocation,
str_to_string_piece(r->headers_out.location->value));
}
// Manually copy over the content type because it's not included in // Manually copy over the content type because it's not included in
// request_->headers_out.headers. // request_->headers_out.headers.
headers->Add(HttpAttributes::kContentType, headers->Add(HttpAttributes::kContentType,
+8
View File
@@ -1241,6 +1241,14 @@ check_from "$OUT" fgrep -qi '404'
MATCHES=$(echo "$OUT" | grep -c "Cache-Control: override") || true MATCHES=$(echo "$OUT" | grep -c "Cache-Control: override") || true
check [ $MATCHES -eq 1 ] check [ $MATCHES -eq 1 ]
start_test Custom 404 does not crash.
URL=http://custom404.example.com/mod_pagespeed_test/
URL+=A.doesnotexist.css.pagespeed.cf.0.css
# The 404 response makes wget exit with an error code, which we ignore.
OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET_DUMP -O /dev/null -S $URL 2>&1) || true
# We ignored the exit code, check if we got a 404 response.
check_from "$OUT" fgrep -qi '404'
start_test Shutting down. start_test Shutting down.
# Fire up some heavy load if ab is available to test a stressed shutdown # Fire up some heavy load if ab is available to test a stressed shutdown
+8
View File
@@ -967,6 +967,14 @@ http {
} }
} }
server {
listen @@SECONDARY_PORT@@;
listen [::]:@@SECONDARY_PORT@@;
server_name custom404.example.com;
pagespeed FileCachePath "@@SECONDARY_CACHE@@";
error_page 404 /404.html;
}
server { server {
listen @@SECONDARY_PORT@@; listen @@SECONDARY_PORT@@;
listen [::]:@@SECONDARY_PORT@@; listen [::]:@@SECONDARY_PORT@@;