summaryrefslogtreecommitdiff
path: root/main/tcptls.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2017-04-10 17:45:35 -0500
committerRichard Mudgett <rmudgett@digium.com>2017-04-11 11:13:39 -0500
commitd76bc0565c070e329e47bd108d8b6218c3233770 (patch)
tree97e9e42622ff98ca5c1cf055bcc5e87343d19c72 /main/tcptls.c
parent2b8dbc9e00094ad0913fa56580266086fc120f3c (diff)
tcptls.c: Cleanup TCP/TLS listener thread on abnormal exit.
Temporarily running out of file descriptors should not terminate the listener thread. Otherwise, when there becomes more file descriptors available, nothing is listening. * Added EMFILE exception to abnormal thread exit. * Added an abnormal TCP/TLS listener exit error message. * Closed the TCP/TLS listener socket on abnormal exit so Asterisk does not appear dead if something tries to connect to the socket. ASTERISK-26903 #close Change-Id: I10f2f784065136277f271159f0925927194581b5
Diffstat (limited to 'main/tcptls.c')
-rw-r--r--main/tcptls.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/main/tcptls.c b/main/tcptls.c
index 1377dd72d..a3c7dfa72 100644
--- a/main/tcptls.c
+++ b/main/tcptls.c
@@ -228,14 +228,23 @@ void *ast_tcptls_server_root(void *data)
}
i = ast_wait_for_input(desc->accept_fd, desc->poll_timeout);
if (i <= 0) {
+ /* Prevent tight loop from hogging CPU */
+ usleep(1);
continue;
}
fd = ast_accept(desc->accept_fd, &addr);
if (fd < 0) {
- if ((errno != EAGAIN) && (errno != EWOULDBLOCK) && (errno != EINTR) && (errno != ECONNABORTED)) {
- ast_log(LOG_ERROR, "Accept failed: %s\n", strerror(errno));
- break;
+ if (errno != EAGAIN
+ && errno != EWOULDBLOCK
+ && errno != EINTR
+ && errno != ECONNABORTED) {
+ ast_log(LOG_ERROR, "TCP/TLS accept failed: %s\n", strerror(errno));
+ if (errno != EMFILE) {
+ break;
+ }
}
+ /* Prevent tight loop from hogging CPU */
+ usleep(1);
continue;
}
tcptls_session = ao2_alloc(sizeof(*tcptls_session), session_instance_destructor);
@@ -267,10 +276,20 @@ void *ast_tcptls_server_root(void *data)
/* This thread is now the only place that controls the single ref to tcptls_session */
if (ast_pthread_create_detached_background(&launched, NULL, handle_tcptls_connection, tcptls_session)) {
- ast_log(LOG_ERROR, "Unable to launch helper thread: %s\n", strerror(errno));
+ ast_log(LOG_ERROR, "TCP/TLS unable to launch helper thread: %s\n",
+ strerror(errno));
ao2_ref(tcptls_session, -1);
}
}
+
+ ast_log(LOG_ERROR, "TCP/TLS listener thread ended abnormally\n");
+
+ /* Close the listener socket so Asterisk doesn't appear dead. */
+ fd = desc->accept_fd;
+ desc->accept_fd = -1;
+ if (0 <= fd) {
+ close(fd);
+ }
return NULL;
}