From 1464140fce325381177af5aa7bdd114800ce3cb2 Mon Sep 17 00:00:00 2001
From: Willy Tarreau <w@1wt.eu>
Date: Tue, 29 Dec 2009 14:49:56 +0100
Subject: [PATCH] [MEDIUM] session: set SI_FL_NOLINGER when aborting on write
 timeouts

Doing this helps us flush the system buffers from all unread data. This
avoids having orphans when clients suddenly get off the net without
reading their entire response.
---
 src/session.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/session.c b/src/session.c
index 2261c932d..a22a6f347 100644
--- a/src/session.c
+++ b/src/session.c
@@ -668,19 +668,23 @@ struct task *process_session(struct task *t)
 
 		buffer_check_timeouts(s->req);
 
+		if (unlikely((s->req->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT)) {
+			s->req->cons->flags |= SI_FL_NOLINGER;
+			s->req->cons->shutw(s->req->cons);
+		}
+
 		if (unlikely((s->req->flags & (BF_SHUTR|BF_READ_TIMEOUT)) == BF_READ_TIMEOUT))
 			s->req->prod->shutr(s->req->prod);
 
-		if (unlikely((s->req->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT))
-			s->req->cons->shutw(s->req->cons);
-
 		buffer_check_timeouts(s->rep);
 
+		if (unlikely((s->rep->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT)) {
+			s->rep->cons->flags |= SI_FL_NOLINGER;
+			s->rep->cons->shutw(s->rep->cons);
+		}
+
 		if (unlikely((s->rep->flags & (BF_SHUTR|BF_READ_TIMEOUT)) == BF_READ_TIMEOUT))
 			s->rep->prod->shutr(s->rep->prod);
-
-		if (unlikely((s->rep->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT))
-			s->rep->cons->shutw(s->rep->cons);
 	}
 
 	/* 1b: check for low-level errors reported at the stream interface.