Fix segfault

The server transport started reading fractionally too early, leading to
the accept callback not being ready in some cases.
pull/2308/head
Craig Tiller 10 years ago
parent a82fef14b3
commit 825b21cd1f
  1. 5
      src/core/security/server_secure_chttp2.c
  2. 3
      src/core/surface/channel_create.c
  3. 6
      src/core/surface/secure_channel_create.c
  4. 3
      src/core/surface/server_chttp2.c
  5. 20
      src/core/transport/chttp2_transport.c
  6. 7
      src/core/transport/chttp2_transport.h

@ -99,9 +99,10 @@ static void on_secure_transport_setup_done(void *statep,
if (!state->is_shutdown) { if (!state->is_shutdown) {
mdctx = grpc_mdctx_create(); mdctx = grpc_mdctx_create();
transport = grpc_create_chttp2_transport( transport = grpc_create_chttp2_transport(
grpc_server_get_channel_args(state->server), secure_endpoint, NULL, 0, grpc_server_get_channel_args(state->server), secure_endpoint, mdctx,
mdctx, 0); 0);
setup_transport(state, transport, mdctx); setup_transport(state, transport, mdctx);
grpc_chttp2_transport_start_reading(transport, NULL, 0);
} else { } else {
/* We need to consume this here, because the server may already have gone /* We need to consume this here, because the server may already have gone
* away. */ * away. */

@ -72,7 +72,8 @@ static void connected(void *arg, grpc_endpoint *tcp) {
grpc_iomgr_closure *notify; grpc_iomgr_closure *notify;
if (tcp != NULL) { if (tcp != NULL) {
c->result->transport = grpc_create_chttp2_transport( c->result->transport = grpc_create_chttp2_transport(
c->args.channel_args, tcp, NULL, 0, c->args.metadata_context, 1); c->args.channel_args, tcp, c->args.metadata_context, 1);
grpc_chttp2_transport_start_reading(c->result->transport, NULL, 0);
GPR_ASSERT(c->result->transport); GPR_ASSERT(c->result->transport);
c->result->filters = gpr_malloc(sizeof(grpc_channel_filter *)); c->result->filters = gpr_malloc(sizeof(grpc_channel_filter *));
c->result->filters[0] = &grpc_http_client_filter; c->result->filters[0] = &grpc_http_client_filter;

@ -82,9 +82,9 @@ static void on_secure_transport_setup_done(void *arg,
gpr_log(GPR_ERROR, "Secure transport setup failed with error %d.", status); gpr_log(GPR_ERROR, "Secure transport setup failed with error %d.", status);
memset(c->result, 0, sizeof(*c->result)); memset(c->result, 0, sizeof(*c->result));
} else { } else {
c->result->transport = c->result->transport = grpc_create_chttp2_transport(
grpc_create_chttp2_transport(c->args.channel_args, secure_endpoint, c->args.channel_args, secure_endpoint, c->args.metadata_context, 1);
NULL, 0, c->args.metadata_context, 1); grpc_chttp2_transport_start_reading(c->result->transport, NULL, 0);
c->result->filters = gpr_malloc(sizeof(grpc_channel_filter *) * 2); c->result->filters = gpr_malloc(sizeof(grpc_channel_filter *) * 2);
c->result->filters[0] = &grpc_client_auth_filter; c->result->filters[0] = &grpc_client_auth_filter;
c->result->filters[1] = &grpc_http_client_filter; c->result->filters[1] = &grpc_http_client_filter;

@ -61,8 +61,9 @@ static void new_transport(void *server, grpc_endpoint *tcp) {
*/ */
grpc_mdctx *mdctx = grpc_mdctx_create(); grpc_mdctx *mdctx = grpc_mdctx_create();
grpc_transport *transport = grpc_create_chttp2_transport( grpc_transport *transport = grpc_create_chttp2_transport(
grpc_server_get_channel_args(server), tcp, NULL, 0, mdctx, 0); grpc_server_get_channel_args(server), tcp, mdctx, 0);
setup_transport(server, transport, mdctx); setup_transport(server, transport, mdctx);
grpc_chttp2_transport_start_reading(transport, NULL, 0);
} }
/* Server callback: start listening on our ports */ /* Server callback: start listening on our ports */

@ -201,8 +201,8 @@ static void ref_transport(grpc_chttp2_transport *t) { gpr_ref(&t->refs); }
static void init_transport(grpc_chttp2_transport *t, static void init_transport(grpc_chttp2_transport *t,
const grpc_channel_args *channel_args, const grpc_channel_args *channel_args,
grpc_endpoint *ep, gpr_slice *slices, size_t nslices, grpc_endpoint *ep, grpc_mdctx *mdctx,
grpc_mdctx *mdctx, int is_client) { int is_client) {
size_t i; size_t i;
int j; int j;
@ -311,9 +311,6 @@ static void init_transport(grpc_chttp2_transport *t,
} }
} }
} }
REF_TRANSPORT(t, "recv_data"); /* matches unref inside recv_data */
recv_data(t, slices, nslices, GRPC_ENDPOINT_CB_OK);
} }
static void destroy_transport(grpc_transport *gt) { static void destroy_transport(grpc_transport *gt) {
@ -1043,9 +1040,16 @@ static const grpc_transport_vtable vtable = {
perform_transport_op, destroy_stream, destroy_transport}; perform_transport_op, destroy_stream, destroy_transport};
grpc_transport *grpc_create_chttp2_transport( grpc_transport *grpc_create_chttp2_transport(
const grpc_channel_args *channel_args, grpc_endpoint *ep, gpr_slice *slices, const grpc_channel_args *channel_args, grpc_endpoint *ep, grpc_mdctx *mdctx,
size_t nslices, grpc_mdctx *mdctx, int is_client) { int is_client) {
grpc_chttp2_transport *t = gpr_malloc(sizeof(grpc_chttp2_transport)); grpc_chttp2_transport *t = gpr_malloc(sizeof(grpc_chttp2_transport));
init_transport(t, channel_args, ep, slices, nslices, mdctx, is_client); init_transport(t, channel_args, ep, mdctx, is_client);
return &t->base; return &t->base;
} }
void grpc_chttp2_transport_start_reading(grpc_transport *transport,
gpr_slice *slices, size_t nslices) {
grpc_chttp2_transport *t = (grpc_chttp2_transport *)transport;
REF_TRANSPORT(t, "recv_data"); /* matches unref inside recv_data */
recv_data(t, slices, nslices, GRPC_ENDPOINT_CB_OK);
}

@ -41,7 +41,10 @@ extern int grpc_http_trace;
extern int grpc_flowctl_trace; extern int grpc_flowctl_trace;
grpc_transport *grpc_create_chttp2_transport( grpc_transport *grpc_create_chttp2_transport(
const grpc_channel_args *channel_args, grpc_endpoint *ep, gpr_slice *slices, const grpc_channel_args *channel_args, grpc_endpoint *ep,
size_t nslices, grpc_mdctx *metadata_context, int is_client); grpc_mdctx *metadata_context, int is_client);
void grpc_chttp2_transport_start_reading(grpc_transport *transport,
gpr_slice *slices, size_t nslices);
#endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_TRANSPORT_H */ #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_TRANSPORT_H */

Loading…
Cancel
Save