diff options
author | David Garcia Quintas <dgq@google.com> | 2017-01-25 08:16:09 -0800 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2017-01-25 10:34:59 -0800 |
commit | 80cc39009fec5242249eb8765be20c02f8d666b5 (patch) | |
tree | de80906f639bec6e3b22d30f53dcd689405094a5 /src/core | |
parent | 6e0697cd3afe1eb0232456c47734cf2b0acf7abb (diff) |
Fixed stream ref issue
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ext/transport/chttp2/transport/writing.c | 21 |
1 files changed, 17 insertions, 4 deletions
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; |