From 60e63d41e18ccd57482fc9df1455513e080f7220 Mon Sep 17 00:00:00 2001
From: Craig Tiller <ctiller@google.com>
Date: Wed, 14 Dec 2016 07:23:42 -0800
Subject: [PATCH] Fixes

---
 .../ext/transport/chttp2/transport/chttp2_transport.c  | 10 +++++-----
 src/core/lib/surface/call.c                            |  5 +++++
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c
index 6a2a54a660..8bfacfac67 100644
--- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c
+++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c
@@ -1560,7 +1560,6 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx,
     return;
   }
   if (close_reads && !s->read_closed) {
-    grpc_chttp2_fake_status(exec_ctx, t, s, GRPC_ERROR_REF(error));
     s->read_closed_error = GRPC_ERROR_REF(error);
     s->read_closed = true;
     for (int i = 0; i < 2; i++) {
@@ -1571,22 +1570,23 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx,
     decrement_active_streams_locked(exec_ctx, t, s);
     grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s);
     grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s);
-    grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
   }
   if (close_writes && !s->write_closed) {
     s->write_closed_error = GRPC_ERROR_REF(error);
     s->write_closed = true;
     grpc_chttp2_fail_pending_writes(exec_ctx, t, s, GRPC_ERROR_REF(error));
-    grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
   }
   if (s->read_closed && s->write_closed) {
+    grpc_error *overall_error =
+        removal_error(GRPC_ERROR_REF(error), s, "Stream removed");
     if (s->id != 0) {
-      remove_stream(exec_ctx, t, s->id,
-                    removal_error(GRPC_ERROR_REF(error), s, "Stream removed"));
+      remove_stream(exec_ctx, t, s->id, GRPC_ERROR_REF(overall_error));
     } else {
       /* Purge streams waiting on concurrency still waiting for id assignment */
       grpc_chttp2_list_remove_waiting_for_concurrency(t, s);
     }
+    grpc_chttp2_fake_status(exec_ctx, t, s, overall_error);
+    grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
     GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2");
   }
   GRPC_ERROR_UNREF(error);
diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c
index 17fda435aa..38b6225abd 100644
--- a/src/core/lib/surface/call.c
+++ b/src/core/lib/surface/call.c
@@ -627,6 +627,11 @@ static void get_final_status(grpc_call *call,
 
 static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call,
                                   status_source source, grpc_error *error) {
+  const char *es = grpc_error_string(error);
+  gpr_log(GPR_DEBUG, "%p[%d]: set %d[is_set=%d] to %s", call, call->is_client,
+          source, call->status[source].is_set, es);
+  grpc_error_free_string(es);
+
   if (call->status[source].is_set) {
     GRPC_ERROR_UNREF(error);
     return;
-- 
GitLab