Skip to content

Commit

Permalink
core,netty: fix a race for channelz at server transport creation
Browse files Browse the repository at this point in the history
  • Loading branch information
dapengzhang0 committed Jan 15, 2020
1 parent 1b5d61f commit 98b11bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/io/grpc/internal/ServerImpl.java
Expand Up @@ -439,7 +439,9 @@ class TransportShutdownNow implements Runnable {
@Override public void run() {}
}, null);
}
channelz.addServerSocket(ServerImpl.this, transport);
synchronized (lock) {
channelz.addServerSocket(ServerImpl.this, transport);
}
}

@Override
Expand Down
17 changes: 4 additions & 13 deletions netty/src/main/java/io/grpc/netty/NettyServer.java
Expand Up @@ -251,19 +251,10 @@ public void operationComplete(ChannelFuture future) throws Exception {
throw new IOException("Failed to bind", future.cause());
}
channel = future.channel();
Future<?> channelzFuture = channel.eventLoop().submit(new Runnable() {
@Override
public void run() {
InternalInstrumented<SocketStats> listenSocket = new ListenSocket(channel);
listenSocketStats.set(listenSocket);
channelz.addListenSocket(listenSocket);
}
});
try {
channelzFuture.await();
} catch (InterruptedException ex) {
throw new RuntimeException("Interrupted while registering listen socket to channelz", ex);
}

InternalInstrumented<SocketStats> listenSocket = new ListenSocket(channel);
listenSocketStats.set(listenSocket);
channelz.addListenSocket(listenSocket);
}

@Override
Expand Down

0 comments on commit 98b11bd

Please sign in to comment.