[asterisk-commits] sgriepentrog: branch 11 r411463 - in /branches/11: ./ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 28 11:16:59 CDT 2014
Author: sgriepentrog
Date: Fri Mar 28 11:16:53 2014
New Revision: 411463
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=411463
Log:
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
Modified:
branches/11/ (props changed)
branches/11/main/http.c
branches/11/main/manager.c
branches/11/main/tcptls.c
Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: branches/11/main/http.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/http.c?view=diff&rev=411463&r1=411462&r2=411463
==============================================================================
--- branches/11/main/http.c (original)
+++ branches/11/main/http.c Fri Mar 28 11:16:53 2014
@@ -433,7 +433,9 @@
/* send content */
if (method != AST_HTTP_HEAD || status_code >= 400) {
if (out) {
- fprintf(ser->f, "%s", ast_str_buffer(out));
+ if (fwrite(ast_str_buffer(out), content_length, 1, ser->f) != 1) {
+ ast_log(LOG_ERROR, "fwrite() failed: %s\n", strerror(errno));
+ }
}
if (fd) {
@@ -455,8 +457,7 @@
ast_free(out);
}
- fclose(ser->f);
- ser->f = 0;
+ ast_tcptls_close_session_file(ser);
return;
}
Modified: branches/11/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/manager.c?view=diff&rev=411463&r1=411462&r2=411463
==============================================================================
--- branches/11/main/manager.c (original)
+++ branches/11/main/manager.c Fri Mar 28 11:16:53 2014
@@ -1491,6 +1491,15 @@
}
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) {
@@ -6413,12 +6422,21 @@
}
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));
}
Modified: branches/11/main/tcptls.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/tcptls.c?view=diff&rev=411463&r1=411462&r2=411463
==============================================================================
--- branches/11/main/tcptls.c (original)
+++ branches/11/main/tcptls.c Fri Mar 28 11:16:53 2014
@@ -625,12 +625,22 @@
void ast_tcptls_close_session_file(struct ast_tcptls_session_instance *tcptls_session)
{
if (tcptls_session->f) {
+ /*
+ * Issuing shutdown() is necessary here to avoid a race
+ * condition where the last data written may not appear
+ * in the TCP stream. See ASTERISK-23548
+ */
+ fflush(tcptls_session->f);
+ if (tcptls_session->fd != -1) {
+ shutdown(tcptls_session->fd, SHUT_RDWR);
+ }
if (fclose(tcptls_session->f)) {
ast_log(LOG_ERROR, "fclose() failed: %s\n", strerror(errno));
}
tcptls_session->f = NULL;
tcptls_session->fd = -1;
} else if (tcptls_session->fd != -1) {
+ shutdown(tcptls_session->fd, SHUT_RDWR);
if (close(tcptls_session->fd)) {
ast_log(LOG_ERROR, "close() failed: %s\n", strerror(errno));
}
More information about the asterisk-commits
mailing list