Skip to content

Commit

Permalink
Merge pull request grpc#7320 from yang-g/shut_down_acceptor_early
Browse files Browse the repository at this point in the history
Shutdown the listeners early when destroying the tcp_server
  • Loading branch information
nicolasnoble authored Jul 22, 2016
2 parents 93da284 + c76e48b commit da9af33
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static void start(grpc_exec_ctx *exec_ctx, grpc_server *server, void *tcpp,
static void destroy(grpc_exec_ctx *exec_ctx, grpc_server *server, void *tcpp,
grpc_closure *destroy_done) {
grpc_tcp_server *tcp = tcpp;
grpc_tcp_server_shutdown_listeners(exec_ctx, tcp);
grpc_tcp_server_unref(exec_ctx, tcp);
grpc_exec_ctx_sched(exec_ctx, destroy_done, GRPC_ERROR_NONE, NULL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ static void destroy(grpc_exec_ctx *exec_ctx, grpc_server *server, void *statep,
state->destroy_callback = callback;
tcp = state->tcp;
gpr_mu_unlock(&state->mu);
grpc_tcp_server_shutdown_listeners(exec_ctx, tcp);
grpc_tcp_server_unref(exec_ctx, tcp);
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/lib/iomgr/tcp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server *s,
a call (exec_ctx!=NULL) to shutdown_complete. */
void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s);

/* Shutdown the fds of listeners. */
void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx *exec_ctx,
grpc_tcp_server *s);

#endif /* GRPC_CORE_LIB_IOMGR_TCP_SERVER_H */
13 changes: 13 additions & 0 deletions src/core/lib/iomgr/tcp_server_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,4 +741,17 @@ void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
}
}

void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx *exec_ctx,
grpc_tcp_server *s) {
gpr_mu_lock(&s->mu);
/* shutdown all fd's */
if (s->active_ports) {
grpc_tcp_listener *sp;
for (sp = s->head; sp; sp = sp->next) {
grpc_fd_shutdown(exec_ctx, sp->emfd);
}
}
gpr_mu_unlock(&s->mu);
}

#endif
3 changes: 3 additions & 0 deletions src/core/lib/iomgr/tcp_server_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,4 +540,7 @@ void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s,
gpr_mu_unlock(&s->mu);
}

void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx *exec_ctx,
grpc_tcp_server *s) {}

#endif /* GPR_WINSOCK_SOCKET */

0 comments on commit da9af33

Please sign in to comment.