Skip to content
Snippets Groups Projects
Commit 2f25d98b authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

properly decrement active_ports

parent 7716c53a
No related branches found
No related tags found
No related merge requests found
...@@ -186,6 +186,17 @@ error: ...@@ -186,6 +186,17 @@ error:
return -1; return -1;
} }
static void decrement_active_ports_and_notify(server_port *sp) {
sp->shutting_down = 0;
sp->socket->read_info.outstanding = 0;
gpr_mu_lock(&sp->server->mu);
GPR_ASSERT(sp->server->active_ports > 0);
if (0 == --sp->server->active_ports) {
gpr_cv_broadcast(&sp->server->cv);
}
gpr_mu_unlock(&sp->server->mu);
}
/* start_accept will reference that for the IOCP notification request. */ /* start_accept will reference that for the IOCP notification request. */
static void on_accept(void *arg, int from_iocp); static void on_accept(void *arg, int from_iocp);
...@@ -234,6 +245,11 @@ static void start_accept(server_port *port) { ...@@ -234,6 +245,11 @@ static void start_accept(server_port *port) {
return; return;
failure: failure:
if (port->shutting_down) {
/* We are abandoning the listener port, take that into account to prevent
occasional hangs on shutdown. */
decrement_active_ports_and_notify(port);
}
utf8_message = gpr_format_message(WSAGetLastError()); utf8_message = gpr_format_message(WSAGetLastError());
gpr_log(GPR_ERROR, message, utf8_message); gpr_log(GPR_ERROR, message, utf8_message);
gpr_free(utf8_message); gpr_free(utf8_message);
...@@ -277,14 +293,7 @@ static void on_accept(void *arg, int from_iocp) { ...@@ -277,14 +293,7 @@ static void on_accept(void *arg, int from_iocp) {
if (sp->shutting_down) { if (sp->shutting_down) {
/* During the shutdown case, we ARE expecting an error. So that's well, /* During the shutdown case, we ARE expecting an error. So that's well,
and we can wake up the shutdown thread. */ and we can wake up the shutdown thread. */
sp->shutting_down = 0; decrement_active_ports_and_notify(sp);
sp->socket->read_info.outstanding = 0;
gpr_mu_lock(&sp->server->mu);
GPR_ASSERT(sp->server->active_ports > 0);
if (0 == --sp->server->active_ports) {
gpr_cv_broadcast(&sp->server->cv);
}
gpr_mu_unlock(&sp->server->mu);
return; return;
} else { } else {
char *utf8_message = gpr_format_message(WSAGetLastError()); char *utf8_message = gpr_format_message(WSAGetLastError());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment