Opened 8 years ago

Closed 8 years ago

#1053 closed defect (invalid)

socket regression from 1.7.4

Reported by: paul.m.lush@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.11.x
Keywords: Cc:
uname -a: Linux www 3.18.12-031812-generic #201504221338 SMP Wed Apr 22 17:39:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.7.5
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf --prefix=/usr --sbin-path=/usr/sbin --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --user=www-data --group=www-data --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_autoindex_module --without-http_ssi_module --with-http_realip_module

Description

I've tracked this back to a change made to 1.7.4 which appears in 1.7.5 onwards, including the most recent version

This is tested in PHP as FPM

  • post.php

<?php
@file_put_contents("/tmp/POSTtest.txt", json_encode($_POST) . "\n", FILE_APPEND);

then using this code if you post to that script you get different results in <= 1.7.4 and => 1.7.5

<?php

$data = http_build_query(array("username" => "testing"));
$fp = @fsockopen("127.0.0.1", 80);
fputs($fp, "POST /post.php HTTP/1.1\n" );
fputs($fp, "Host: www.myhost.com\n" );
fputs($fp, "Content-type: application/x-www-form-urlencoded\n" );
fputs($fp, "Content-length: ".strlen($data)."\n" );
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
while(!feof($fp)) { $h = fgets($fp, 128); }
fclose($fp);

in 1.7.4 and below, you will get post.php logging the post data to the log file. In 1.7.5, it won't log any data unless you uncommand the while loop and read back the data. Nothing in the changelog suggests a change to the way the cgi connection is handled or a change to buffering

Change History (2)

comment:1 by paul.m.lush@…, 8 years ago

Sorry, formatting below up, the PHP code is it should display

<?php
$data = http_build_query(array("username" => "testing"));
$fp = @fsockopen("127.0.0.1", 80);
fputs($fp, "POST /post.php HTTP/1.1\n" );
fputs($fp, "Host: www.myhost.com\n" );
fputs($fp, "Content-type: application/x-www-form-urlencoded\n" );
fputs($fp, "Content-length: ".strlen($data)."\n" );
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
// while(!feof($fp)) { $h = fgets($fp, 128); }
fclose($fp);

comment:2 by Maxim Dounin, 8 years ago

Resolution: invalid
Status: newclosed

The code in question is not expected to work reliably, as nginx will stop processing the request as long as it will detect the connection was closed. It may work or not depending on various timing factors. To make nginx ignore connection close by clients while talking to FastCGI backends, consider using fastcgi_ignore_client_abort.

Note: See TracTickets for help on using tickets.