Commit 835a0722 authored by Tollef Fog Heen's avatar Tollef Fog Heen

Add proper handling of TCP timeouts on client side

Retry if we hit a TCP timeout if some data was sent and only error out
when we get an error or no data was sent in the time period.
parent 8332ca86
......@@ -123,7 +123,37 @@ WRW_Flush(struct worker *w)
wrw->iov[wrw->ciov].iov_len = 0;
}
i = writev(*wrw->wfd, wrw->iov, wrw->niov);
if (i != wrw->liov) {
while (i != wrw->liov && i > 0) {
/* Remove sent data from start of I/O vector,
* then retry; we hit a timeout, but some data
* was sent.
XXX: Add a "minimum sent data per timeout
counter to prevent slowlaris attacks
*/
size_t used = 0;
WSL(w, SLT_Debug, *wrw->wfd,
"Hit send timeout, wrote = %ld/%ld; retrying",
i, wrw->liov);
for (int j = 0; j < wrw->niov; j++) {
if (used + wrw->iov[j].iov_len > i) {
/* Cutoff is in this iov */
int used_here = i - used;
wrw->iov[j].iov_len -= used_here;
wrw->iov[j].iov_base = (char*)wrw->iov[j].iov_base + used_here;
memmove(wrw->iov, &wrw->iov[j],
(wrw->niov - j) * sizeof(struct iovec));
wrw->niov -= j;
wrw->liov -= i;
break;
}
used += wrw->iov[j].iov_len;
}
i = writev(*wrw->wfd, wrw->iov, wrw->niov);
}
if (i <= 0) {
wrw->werr++;
WSL(w, SLT_Debug, *wrw->wfd,
"Write error, retval = %d, len = %d, errno = %s",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment