diff options
author | 2015-06-30 16:05:39 -0700 | |
---|---|---|
committer | 2015-06-30 16:05:39 -0700 | |
commit | 3e57357aff574e54aaeeaae98c3e5aac41b50e63 (patch) | |
tree | 6e56f1d8acb609abe7daa2f344265718e2100b22 /src | |
parent | 9d8830da38f83fb2a9260e30fdd3b6e5785d42b3 (diff) | |
parent | 0d4836d2c5de2cef30015d3f62a9cca511daacda (diff) |
Merge pull request #2263 from ctiller/with-what-shall-we-mend-it-dear-liza-dear-liza
Remove the ability to specify a cancellation string
Diffstat (limited to 'src')
-rw-r--r-- | src/core/security/security_connector.c | 13 | ||||
-rw-r--r-- | src/core/security/security_context.c | 31 | ||||
-rw-r--r-- | src/core/security/security_context.h | 19 | ||||
-rw-r--r-- | src/core/security/server_auth_filter.c | 8 | ||||
-rw-r--r-- | src/core/transport/chttp2/incoming_metadata.c | 4 | ||||
-rw-r--r-- | src/core/transport/chttp2_transport.c | 32 | ||||
-rw-r--r-- | src/core/transport/metadata.c | 2 | ||||
-rw-r--r-- | src/core/transport/transport.c | 4 | ||||
-rw-r--r-- | src/core/transport/transport.h | 1 | ||||
-rw-r--r-- | src/core/transport/transport_op_string.c | 5 |
10 files changed, 84 insertions, 35 deletions
diff --git a/src/core/security/security_connector.c b/src/core/security/security_connector.c index 5512bb177a..34cb0395a2 100644 --- a/src/core/security/security_connector.c +++ b/src/core/security/security_connector.c @@ -196,12 +196,12 @@ typedef struct { static void fake_channel_destroy(grpc_security_connector *sc) { grpc_channel_security_connector *c = (grpc_channel_security_connector *)sc; grpc_credentials_unref(c->request_metadata_creds); - grpc_auth_context_unref(sc->auth_context); + GRPC_AUTH_CONTEXT_UNREF(sc->auth_context, "connector"); gpr_free(sc); } static void fake_server_destroy(grpc_security_connector *sc) { - grpc_auth_context_unref(sc->auth_context); + GRPC_AUTH_CONTEXT_UNREF(sc->auth_context, "connector"); gpr_free(sc); } @@ -242,7 +242,7 @@ static grpc_security_status fake_check_peer(grpc_security_connector *sc, status = GRPC_SECURITY_ERROR; goto end; } - grpc_auth_context_unref(sc->auth_context); + GRPC_AUTH_CONTEXT_UNREF(sc->auth_context, "connector"); sc->auth_context = grpc_auth_context_create(NULL, 1); sc->auth_context->properties[0] = grpc_auth_property_init_from_cstring( GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, @@ -323,7 +323,7 @@ static void ssl_channel_destroy(grpc_security_connector *sc) { if (c->target_name != NULL) gpr_free(c->target_name); if (c->overridden_target_name != NULL) gpr_free(c->overridden_target_name); tsi_peer_destruct(&c->peer); - grpc_auth_context_unref(sc->auth_context); + GRPC_AUTH_CONTEXT_UNREF(sc->auth_context, "connector"); gpr_free(sc); } @@ -333,7 +333,7 @@ static void ssl_server_destroy(grpc_security_connector *sc) { if (c->handshaker_factory != NULL) { tsi_ssl_handshaker_factory_destroy(c->handshaker_factory); } - grpc_auth_context_unref(sc->auth_context); + GRPC_AUTH_CONTEXT_UNREF(sc->auth_context, "connector"); gpr_free(sc); } @@ -437,6 +437,9 @@ static grpc_security_status ssl_check_peer(grpc_security_connector *sc, gpr_log(GPR_ERROR, "Peer name %s is not in peer certificate", peer_name); return GRPC_SECURITY_ERROR; } + if (sc->auth_context != NULL) { + GRPC_AUTH_CONTEXT_UNREF(sc->auth_context, "connector"); + } sc->auth_context = tsi_ssl_peer_to_auth_context(peer); return GRPC_SECURITY_OK; } diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c index 9aba1e7f91..4d56549f9b 100644 --- a/src/core/security/security_context.c +++ b/src/core/security/security_context.c @@ -89,7 +89,7 @@ grpc_client_security_context *grpc_client_security_context_create(void) { void grpc_client_security_context_destroy(void *ctx) { grpc_client_security_context *c = (grpc_client_security_context *)ctx; grpc_credentials_unref(c->creds); - grpc_auth_context_unref(c->auth_context); + GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context"); gpr_free(ctx); } @@ -104,7 +104,7 @@ grpc_server_security_context *grpc_server_security_context_create(void) { void grpc_server_security_context_destroy(void *ctx) { grpc_server_security_context *c = (grpc_server_security_context *)ctx; - grpc_auth_context_unref(c->auth_context); + GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "server_security_context"); gpr_free(ctx); } @@ -120,21 +120,40 @@ grpc_auth_context *grpc_auth_context_create(grpc_auth_context *chained, memset(ctx->properties, 0, property_count * sizeof(grpc_auth_property)); ctx->property_count = property_count; gpr_ref_init(&ctx->refcount, 1); - if (chained != NULL) ctx->chained = grpc_auth_context_ref(chained); + if (chained != NULL) ctx->chained = GRPC_AUTH_CONTEXT_REF(chained, "chained"); return ctx; } +#ifdef GRPC_AUTH_CONTEXT_REFCOUNT_DEBUG +grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *ctx, + const char *file, int line, + const char *reason) { + if (ctx == NULL) return NULL; + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, + "AUTH_CONTEXT:%p ref %d -> %d %s", ctx, (int)ctx->refcount.count, + (int)ctx->refcount.count + 1, reason); +#else grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *ctx) { if (ctx == NULL) return NULL; +#endif gpr_ref(&ctx->refcount); return ctx; } +#ifdef GRPC_AUTH_CONTEXT_REFCOUNT_DEBUG +void grpc_auth_context_unref(grpc_auth_context *ctx, const char *file, int line, + const char *reason) { + if (ctx == NULL) return; + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, + "AUTH_CONTEXT:%p unref %d -> %d %s", ctx, (int)ctx->refcount.count, + (int)ctx->refcount.count - 1, reason); +#else void grpc_auth_context_unref(grpc_auth_context *ctx) { if (ctx == NULL) return; +#endif if (gpr_unref(&ctx->refcount)) { size_t i; - grpc_auth_context_unref(ctx->chained); + GRPC_AUTH_CONTEXT_UNREF(ctx->chained, "chained"); if (ctx->properties != NULL) { for (i = 0; i < ctx->property_count; i++) { grpc_auth_property_reset(&ctx->properties[i]); @@ -223,8 +242,8 @@ grpc_auth_property grpc_auth_property_init(const char *name, const char *value, } void grpc_auth_property_reset(grpc_auth_property *property) { - if (property->name != NULL) gpr_free(property->name); - if (property->value != NULL) gpr_free(property->value); + gpr_free(property->name); + gpr_free(property->value); memset(property, 0, sizeof(grpc_auth_property)); } diff --git a/src/core/security/security_context.h b/src/core/security/security_context.h index d8909cd6f1..20c4390898 100644 --- a/src/core/security/security_context.h +++ b/src/core/security/security_context.h @@ -55,9 +55,22 @@ grpc_auth_context *grpc_auth_context_create(grpc_auth_context *chained, size_t property_count); /* Refcounting. */ -grpc_auth_context *grpc_auth_context_ref( - grpc_auth_context *ctx); -void grpc_auth_context_unref(grpc_auth_context *ctx); +#ifdef GRPC_AUTH_CONTEXT_REFCOUNT_DEBUG +#define GRPC_AUTH_CONTEXT_REF(p, r) \ + grpc_auth_context_ref((p), __FILE__, __LINE__, (r)) +#define GRPC_AUTH_CONTEXT_UNREF(p, r) \ + grpc_auth_context_unref((p), __FILE__, __LINE__, (r)) +grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *policy, + const char *file, int line, + const char *reason); +void grpc_auth_context_unref(grpc_auth_context *policy, const char *file, + int line, const char *reason); +#else +#define GRPC_AUTH_CONTEXT_REF(p, r) grpc_auth_context_ref((p)) +#define GRPC_AUTH_CONTEXT_UNREF(p, r) grpc_auth_context_unref((p)) +grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *policy); +void grpc_auth_context_unref(grpc_auth_context *policy); +#endif grpc_auth_property grpc_auth_property_init_from_cstring(const char *name, const char *value); diff --git a/src/core/security/server_auth_filter.c b/src/core/security/server_auth_filter.c index b19160b8ed..b8639287a5 100644 --- a/src/core/security/server_auth_filter.c +++ b/src/core/security/server_auth_filter.c @@ -82,9 +82,13 @@ static void init_call_elem(grpc_call_element *elem, /* Create a security context for the call and reference the auth context from the channel. */ + if (initial_op->context[GRPC_CONTEXT_SECURITY].value != NULL) { + initial_op->context[GRPC_CONTEXT_SECURITY].destroy( + initial_op->context[GRPC_CONTEXT_SECURITY].value); + } server_ctx = grpc_server_security_context_create(); - server_ctx->auth_context = - grpc_auth_context_ref(chand->security_connector->auth_context); + server_ctx->auth_context = GRPC_AUTH_CONTEXT_REF( + chand->security_connector->auth_context, "server_security_context"); initial_op->context[GRPC_CONTEXT_SECURITY].value = server_ctx; initial_op->context[GRPC_CONTEXT_SECURITY].destroy = grpc_server_security_context_destroy; diff --git a/src/core/transport/chttp2/incoming_metadata.c b/src/core/transport/chttp2/incoming_metadata.c index e81927ab20..a4b7174329 100644 --- a/src/core/transport/chttp2/incoming_metadata.c +++ b/src/core/transport/chttp2/incoming_metadata.c @@ -47,6 +47,10 @@ void grpc_chttp2_incoming_metadata_buffer_init( void grpc_chttp2_incoming_metadata_buffer_destroy( grpc_chttp2_incoming_metadata_buffer *buffer) { + size_t i; + for (i = 0; i < buffer->count; i++) { + grpc_mdelem_unref(buffer->elems[i].md); + } gpr_free(buffer->elems); } diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c index 94659a6bdf..f938969717 100644 --- a/src/core/transport/chttp2_transport.c +++ b/src/core/transport/chttp2_transport.c @@ -50,8 +50,6 @@ #include <grpc/support/string_util.h> #include <grpc/support/useful.h> -/* #define REFCOUNTING_DEBUG */ - #define DEFAULT_WINDOW 65535 #define DEFAULT_CONNECTION_WINDOW_TARGET (1024 * 1024) #define MAX_WINDOW 0x7fffffffu @@ -436,6 +434,8 @@ static void destroy_stream(grpc_transport *gt, grpc_stream *gs) { grpc_chttp2_data_parser_destroy(&s->parsing.data_parser); grpc_chttp2_incoming_metadata_buffer_destroy(&s->parsing.incoming_metadata); grpc_chttp2_incoming_metadata_buffer_destroy(&s->global.incoming_metadata); + grpc_chttp2_incoming_metadata_live_op_buffer_end( + &s->global.outstanding_metadata); UNREF_TRANSPORT(t, "stream"); } @@ -859,11 +859,22 @@ static void update_global_window(void *args, gpr_uint32 id, void *stream) { stream_global->outgoing_window += t->parsing.initial_window_update; } +static void read_error_locked(grpc_chttp2_transport *t) { + t->endpoint_reading = 0; + if (!t->writing_active && t->ep) { + grpc_endpoint_destroy(t->ep); + t->ep = NULL; + /* safe as we still have a ref for read */ + UNREF_TRANSPORT(t, "disconnect"); + } +} + /* tcp read callback */ static void recv_data(void *tp, gpr_slice *slices, size_t nslices, grpc_endpoint_cb_status error) { grpc_chttp2_transport *t = tp; size_t i; + int unref = 0; switch (error) { case GRPC_ENDPOINT_CB_SHUTDOWN: @@ -871,15 +882,9 @@ static void recv_data(void *tp, gpr_slice *slices, size_t nslices, case GRPC_ENDPOINT_CB_ERROR: lock(t); drop_connection(t); - t->endpoint_reading = 0; - if (!t->writing_active && t->ep) { - grpc_endpoint_destroy(t->ep); - t->ep = NULL; - UNREF_TRANSPORT( - t, "disconnect"); /* safe as we still have a ref for read */ - } + read_error_locked(t); unlock(t); - UNREF_TRANSPORT(t, "recv_data"); + unref = 1; for (i = 0; i < nslices; i++) gpr_slice_unref(slices[i]); break; case GRPC_ENDPOINT_CB_OK: @@ -915,15 +920,22 @@ static void recv_data(void *tp, gpr_slice *slices, size_t nslices, } if (i == nslices) { grpc_chttp2_schedule_closure(&t->global, &t->reading_action, 1); + } else { + read_error_locked(t); + unref = 1; } unlock(t); for (; i < nslices; i++) gpr_slice_unref(slices[i]); break; } + if (unref) { + UNREF_TRANSPORT(t, "recv_data"); + } } static void reading_action(void *pt, int iomgr_success_ignored) { grpc_chttp2_transport *t = pt; + gpr_log(GPR_DEBUG, "reading_action"); grpc_endpoint_notify_on_read(t->ep, recv_data, t); } diff --git a/src/core/transport/metadata.c b/src/core/transport/metadata.c index e75b449e12..c80d67823f 100644 --- a/src/core/transport/metadata.c +++ b/src/core/transport/metadata.c @@ -120,7 +120,7 @@ static void unlock(grpc_mdctx *ctx) { if (ctx->refs == 0) { /* uncomment if you're having trouble diagnosing an mdelem leak to make things clearer (slows down destruction a lot, however) */ - /* gc_mdtab(ctx); */ + gc_mdtab(ctx); if (ctx->mdtab_count && ctx->mdtab_count == ctx->mdtab_free) { discard_metadata(ctx); } diff --git a/src/core/transport/transport.c b/src/core/transport/transport.c index 2f85a8557d..39d7b701f2 100644 --- a/src/core/transport/transport.c +++ b/src/core/transport/transport.c @@ -112,8 +112,8 @@ void grpc_transport_op_add_cancellation(grpc_transport_op *op, grpc_mdstr *message) { if (op->cancel_with_status == GRPC_STATUS_OK) { op->cancel_with_status = status; - op->cancel_message = message; - } else if (message) { + } + if (message) { grpc_mdstr_unref(message); } } diff --git a/src/core/transport/transport.h b/src/core/transport/transport.h index 0a5b31a60a..a2c41c47af 100644 --- a/src/core/transport/transport.h +++ b/src/core/transport/transport.h @@ -77,7 +77,6 @@ typedef struct grpc_transport_op { grpc_pollset *bind_pollset; grpc_status_code cancel_with_status; - grpc_mdstr *cancel_message; /* Indexes correspond to grpc_context_index enum values */ grpc_call_context_element *context; diff --git a/src/core/transport/transport_op_string.c b/src/core/transport/transport_op_string.c index 5c4edb006a..a408b75790 100644 --- a/src/core/transport/transport_op_string.c +++ b/src/core/transport/transport_op_string.c @@ -144,11 +144,6 @@ char *grpc_transport_op_string(grpc_transport_op *op) { first = 0; gpr_asprintf(&tmp, "CANCEL:%d", op->cancel_with_status); gpr_strvec_add(&b, tmp); - if (op->cancel_message) { - gpr_asprintf(&tmp, ";msg='%s'", - grpc_mdstr_as_c_string(op->cancel_message)); - gpr_strvec_add(&b, tmp); - } } out = gpr_strvec_flatten(&b, NULL); |