Forum: NGINX Proposal minor patch on ngx_http_upstream.c

2974d09ac2541e892966b762aad84943?d=identicon&s=25 crespin (Guest)
on 2014-06-02 15:52
(Received via mailing list)
Hello,

errno is only set on error, so if |recv()| is a success, |err| will have
a
random value.
Only debug message are impacted.
Can you check if it is ok?
Comments are welcome.
Feel free to change the patch.

Regards,

yves


---
 nginx-1.6.0/src/http/ngx_http_upstream.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/nginx-1.6.0/src/http/ngx_http_upstream.c
b/nginx-1.6.0/src/http/ngx
index 040bda1..f60acb3 100644
--- a/nginx-1.6.0/src/http/ngx_http_upstream.c
+++ b/nginx-1.6.0/src/http/ngx_http_upstream.c
@@ -1128,7 +1128,7 @@
ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,

     n = recv(c->fd, buf, 1, MSG_PEEK);

-    err = ngx_socket_errno;
+    err = n == 1 ? ngx_socket_errno : 0;

     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err,
                    "http upstream recv(): %d", n);
@@ -1158,9 +1158,6 @@
ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
         }

         ev->error = 1;
-
-    } else { /* n == 0 */
-        err = 0;
     }

     ev->eof = 1;

--
1.7.10.4

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,250570,250570#msg-250570
2154be8b4430488454f0a067e09863b9?d=identicon&s=25 Ruslan Ermilov (Guest)
on 2014-06-02 16:19
(Received via mailing list)
On Mon, Jun 02, 2014 at 09:51:42AM -0400, crespin wrote:
>
> --- a/nginx-1.6.0/src/http/ngx_http_upstream.c
> +++ b/nginx-1.6.0/src/http/ngx_http_upstream.c
> @@ -1128,7 +1128,7 @@
> ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
>
>      n = recv(c->fd, buf, 1, MSG_PEEK);
>
> -    err = ngx_socket_errno;
> +    err = n == 1 ? ngx_socket_errno : 0;

(n == -1)

> -        err = 0;
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>

--
Ruslan Ermilov
2974d09ac2541e892966b762aad84943?d=identicon&s=25 crespin (Guest)
on 2014-06-02 17:37
(Received via mailing list)
Hello Ruslan,

Thanks for your remark.
Is it necessary to send the correct patch ?

Regards,

yves

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,250570,250579#msg-250579
2974d09ac2541e892966b762aad84943?d=identicon&s=25 crespin (Guest)
on 2014-08-08 08:49
(Received via mailing list)
Hello,

Here is the corresponding patch.

Regards,

yves


# HG changeset patch
# User Yves Crespin<yves.crespin@e-quartz.fr>
# Date 1407480323 -7200
# Node ID a62fffc16af816612a4acf34c7a4781f454fa5d1
# Parent  8120c2937062998497546a3ecb38b78bb302fe34
Upstream: ngx_socket_errno can only be used if |recv()| failed

if |recv()| is a success, err will have a random value.
only debug message are impacted.

diff -r 8120c2937062 -r a62fffc16af8 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c  Thu Aug 07 16:04:07 2014 +0200
+++ b/src/http/ngx_http_upstream.c  Fri Aug 08 08:45:23 2014 +0200
@@ -1145,7 +1145,7 @@

     n = recv(c->fd, buf, 1, MSG_PEEK);

-    err = ngx_socket_errno;
+    err = (n == -1) ? ngx_socket_errno : 0;

     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err,
                    "http upstream recv(): %d", n);
@@ -1175,9 +1175,6 @@
         }

         ev->error = 1;
-
-    } else { /* n == 0 */
-        err = 0;
     }

     ev->eof = 1;

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,250570,252403#msg-252403
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.