]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[BUG] stream_sock: fix handling for server side PROXY protocol
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Mar 2011 21:17:54 +0000 (23:17 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Mar 2011 21:17:54 +0000 (23:17 +0200)
Patch 5ab04ec47c9946a2bbc535687c023215ca813da0 was incomplete,
because if the first send() fails on an empty buffer, we fail
to rearm the polling and we can't establish the connection
anymore.

The issue was reported by Ben Timby who provided large amounts
of traces of various tests helping to reliably reproduce the issue.

src/stream_sock.c

index 845aca08cc8dc4cae69b72833ceaf0d10c6194e0..3e9784c28415474d8c7df83afdad07ce8290ed9f 100644 (file)
@@ -751,6 +751,8 @@ int stream_sock_write(int fd)
                retval = stream_sock_write_loop(si, b);
                if (retval < 0)
                        goto out_error;
+               else if (retval == 0 && si->send_proxy_ofs)
+                       goto out_may_wakeup; /* we failed to send the PROXY string */
        }
        else  {
                /* may be we have received a connection acknowledgement in TCP mode without data */
@@ -1112,6 +1114,8 @@ void stream_sock_chk_snd(struct stream_interface *si)
                si->flags |= SI_FL_ERR;
                goto out_wakeup;
        }
+       else if (retval == 0 && si->send_proxy_ofs)
+               goto out_may_wakeup; /* we failed to send the PROXY string */
 
        /* OK, so now we know that retval >= 0 means that some data might have
         * been sent, and that we may have to poll first. We have to do that
@@ -1144,6 +1148,7 @@ void stream_sock_chk_snd(struct stream_interface *si)
                        ob->wex = tick_add_ifset(now_ms, ob->wto);
        }
 
+ out_may_wakeup:
        if (likely(ob->flags & BF_WRITE_ACTIVITY)) {
                /* update timeout if we have written something */
                if ((ob->flags & (BF_OUT_EMPTY|BF_SHUTW|BF_WRITE_PARTIAL)) == BF_WRITE_PARTIAL)