aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-07-09 14:51:24 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-07-09 14:51:24 -0700
commit315feadd4a4fd300226d24e6622ab11a0b6c61eb (patch)
treeb8bae25b994f3e336b7ddafaf92fa8d33ac41930 /src/core
parentb97b988052f628a7831042acd4cfe1ab854e97cf (diff)
Fix race in TCP connection
If the TCP client connection alarm triggers close to the connection deadline (but succeeds), the alarm shuts down the endpoint underneath the existing transport... which is very bad for its health.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/iomgr/tcp_client_posix.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c
index d981aaf028..2c6ff4e9c4 100644
--- a/src/core/iomgr/tcp_client_posix.c
+++ b/src/core/iomgr/tcp_client_posix.c
@@ -114,6 +114,7 @@ static void on_writable(void *acp, int success) {
void (*cb)(void *arg, grpc_endpoint *tcp) = ac->cb;
void *cb_arg = ac->cb_arg;
+ gpr_mu_lock(&ac->mu);
if (success) {
do {
so_error_size = sizeof(so_error);
@@ -139,6 +140,7 @@ static void on_writable(void *acp, int success) {
opened too many network connections. The "easy" fix:
don't do that! */
gpr_log(GPR_ERROR, "kernel out of buffers");
+ gpr_mu_unlock(&ac->mu);
grpc_fd_notify_on_write(ac->fd, &ac->write_closure);
return;
} else {
@@ -165,10 +167,11 @@ static void on_writable(void *acp, int success) {
abort();
finish:
- gpr_mu_lock(&ac->mu);
- if (!ep) {
+ if (ep == NULL) {
grpc_pollset_set_del_fd(ac->interested_parties, ac->fd);
grpc_fd_orphan(ac->fd, NULL, "tcp_client_orphan");
+ } else {
+ ac->fd = NULL;
}
done = (--ac->refs == 0);
gpr_mu_unlock(&ac->mu);