OkHttpClientTransport.onGoAway() races with startPendingStreams()
onGoAway has two phases: do things necessary under lock and final cleanup. In the first phase it collects the streams to terminate in the second and sets goAway.

startPendingStreams() does not observe goAway and also creates new streams that should be failed due to the goAway. From an initial look, it seems it would be best to remove failPendingStreams() and simply integrate its two phases into onGoAway()'s two phases; that is, when holding the lock in onGoAway, replace pendingStreams with an empty list, and then when not holding the lock call transportReportStatus

diff --git a/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpClientTransport.java b/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpClientTransport.java
index 0e37a3884..04fd3612e 100644
--- a/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpClientTransport.java
+++ b/okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpClientTransport.java
@@ -279,19 +279,6 @@ public class OkHttpClientTransport implements ClientTransport {
     return hasStreamStarted;
   }
 
-  private void failPendingStreams(Status status) {
-    LinkedList<PendingStream> streams;
-    synchronized (lock) {
-      streams = pendingStreams;
-      pendingStreams = new LinkedList<PendingStream>();
-    }
-    for (PendingStream stream : streams) {
-      stream.clientStream.transportReportStatus(
-          status, true, new Metadata.Trailers());
-      stream.createdFuture.set(null);
-    }
-  }
-
   @Override
   public void start(Listener listener) {
     this.listener = Preconditions.checkNotNull(listener, "listener");
@@ -368,6 +355,7 @@ public class OkHttpClientTransport implements ClientTransport {
   private void onGoAway(int lastKnownStreamId, Status status) {
     boolean notifyShutdown;
     ArrayList<OkHttpClientStream> goAwayStreams = new ArrayList<OkHttpClientStream>();
+    List<PendingStream> pendingStreamsCopy;
     synchronized (lock) {
       notifyShutdown = !goAway;
       goAway = true;
@@ -382,6 +370,9 @@ public class OkHttpClientTransport implements ClientTransport {
           }
         }
       }
+
+      pendingStreamsCopy = pendingStreams;
+      pendingStreams = new LinkedList<PendingStream>();
     }
 
     if (notifyShutdown) {
@@ -390,7 +381,12 @@ public class OkHttpClientTransport implements ClientTransport {
     for (OkHttpClientStream stream : goAwayStreams) {
       stream.transportReportStatus(status, false, new Metadata.Trailers());
     }
-    failPendingStreams(status);
+
+    for (PendingStream stream : pendingStreamsCopy) {
+      stream.clientStream.transportReportStatus(
+          status, true, new Metadata.Trailers());
+      stream.createdFuture.set(null);
+    }
     stopIfNecessary();
   }
 
['okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpClientTransport.java']