From 80cc39009fec5242249eb8765be20c02f8d666b5 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 25 Jan 2017 08:16:09 -0800 Subject: Fixed stream ref issue --- src/core/ext/transport/chttp2/transport/writing.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/ext/transport/chttp2/transport/writing.c b/src/core/ext/transport/chttp2/transport/writing.c index ef2010af7b..1a61e10685 100644 --- a/src/core/ext/transport/chttp2/transport/writing.c +++ b/src/core/ext/transport/chttp2/transport/writing.c @@ -74,6 +74,15 @@ static void update_list(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, GRPC_ERROR_UNREF(error); } +static bool stream_ref_if_not_destroyed(gpr_refcount *r) { + gpr_atm count; +retry: + count = gpr_atm_acq_load(&r->count); + if (count == 0) return false; + if (!gpr_atm_rel_cas(&r->count, count, count + 1)) goto retry; + return true; +} + bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { grpc_chttp2_stream *s; @@ -101,8 +110,11 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx, if (t->outgoing_window > 0) { while (grpc_chttp2_list_pop_stalled_by_transport(t, &s)) { - grpc_chttp2_become_writable(exec_ctx, t, s, false, - "transport.read_flow_control"); + if (!t->closed && grpc_chttp2_list_add_writable_stream(t, s) && + stream_ref_if_not_destroyed(&s->refcount->refs)) { + grpc_chttp2_initiate_write(exec_ctx, t, false, + "transport.read_flow_control"); + } } } @@ -188,8 +200,9 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx, } else { grpc_chttp2_encode_header( exec_ctx, &t->hpack_compressor, s->id, s->send_trailing_metadata, - true, t->settings[GRPC_ACKED_SETTINGS] - [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], + true, + t->settings[GRPC_ACKED_SETTINGS] + [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], &s->stats.outgoing, &t->outbuf); } s->send_trailing_metadata = NULL; -- cgit v1.2.3 From 84580cc487526239d890abf1bbedccc17ae5629b Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 25 Jan 2017 10:42:12 -0800 Subject: PR comments: do-while in lieu of goto --- src/core/ext/transport/chttp2/transport/writing.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/ext/transport/chttp2/transport/writing.c b/src/core/ext/transport/chttp2/transport/writing.c index 1a61e10685..695b19d69c 100644 --- a/src/core/ext/transport/chttp2/transport/writing.c +++ b/src/core/ext/transport/chttp2/transport/writing.c @@ -76,10 +76,10 @@ static void update_list(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, static bool stream_ref_if_not_destroyed(gpr_refcount *r) { gpr_atm count; -retry: - count = gpr_atm_acq_load(&r->count); - if (count == 0) return false; - if (!gpr_atm_rel_cas(&r->count, count, count + 1)) goto retry; + do { + count = gpr_atm_acq_load(&r->count); + if (count == 0) return false; + } while (!gpr_atm_rel_cas(&r->count, count, count + 1)); return true; } -- cgit v1.2.3 From d8e3e3d544036408dde6bd49f93666075de6d37a Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 25 Jan 2017 13:58:13 -0800 Subject: clang-format --- src/core/ext/transport/chttp2/transport/writing.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/ext/transport/chttp2/transport/writing.c b/src/core/ext/transport/chttp2/transport/writing.c index 695b19d69c..84554d327d 100644 --- a/src/core/ext/transport/chttp2/transport/writing.c +++ b/src/core/ext/transport/chttp2/transport/writing.c @@ -200,9 +200,8 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx, } else { grpc_chttp2_encode_header( exec_ctx, &t->hpack_compressor, s->id, s->send_trailing_metadata, - true, - t->settings[GRPC_ACKED_SETTINGS] - [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], + true, t->settings[GRPC_ACKED_SETTINGS] + [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], &s->stats.outgoing, &t->outbuf); } s->send_trailing_metadata = NULL; -- cgit v1.2.3