http: response body often missing after specific request

This patch works around a problem with the HTTP body
being dropped from the response to a specific client
and under specific circumstances:

a) Client request comes from node.js user agent
   "Shred" via use of swagger-client library.

b) Asterisk and Client are *not* on the same
   host or TCP/IP stack

In testing this problem, it has been determined that
the write of the HTTP body is lost, even if the data
is written using low level write function.  The only
solution found is to instruct the TCP stack with the
shutdown function to flush the last write and finish
the transmission.  See review for more details.


ASTERISK-23548 #close
(closes issue ASTERISK-23548)
Reported by: Sam Galarneau
Review: https://reviewboard.asterisk.org/r/3402/
........

Merged revisions 411462 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 411463 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@411465 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Scott Griepentrog
2014-03-28 16:17:52 +00:00
parent 833d37a15e
commit ed2452a9a5
3 changed files with 32 additions and 3 deletions

View File

@@ -1769,6 +1769,15 @@ static void session_destructor(void *obj)
}
if (session->f != NULL) {
/*
* Issuing shutdown() is necessary here to avoid a race
* condition where the last data written may not appear
* in the the TCP stream. See ASTERISK-23548
*/
fflush(session->f);
if (session->fd != -1) {
shutdown(session->fd, SHUT_RDWR);
}
fclose(session->f);
}
if (eqe) {
@@ -6736,12 +6745,21 @@ static void process_output(struct mansession *s, struct ast_str **out, struct as
}
if (s->f) {
/*
* Issuing shutdown() is necessary here to avoid a race
* condition where the last data written may not appear
* in the the TCP stream. See ASTERISK-23548
*/
if (s->fd != -1) {
shutdown(s->fd, SHUT_RDWR);
}
if (fclose(s->f)) {
ast_log(LOG_ERROR, "fclose() failed: %s\n", strerror(errno));
}
s->f = NULL;
s->fd = -1;
} else if (s->fd != -1) {
shutdown(s->fd, SHUT_RDWR);
if (close(s->fd)) {
ast_log(LOG_ERROR, "close() failed: %s\n", strerror(errno));
}