File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed
java/src/org/openqa/selenium/grid/commands Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change 2626import com .google .auto .service .AutoService ;
2727import com .google .common .collect .ImmutableMap ;
2828import com .google .common .collect .ImmutableSet ;
29+ import java .util .ArrayList ;
2930import java .util .Collections ;
31+ import java .util .List ;
3032import java .util .Set ;
3133import java .util .concurrent .CountDownLatch ;
3234import java .util .concurrent .TimeUnit ;
@@ -107,6 +109,24 @@ public Server<?> asServer(Config initialConfig) {
107109 EventBus bus = events .getEventBus ();
108110
109111 BaseServerOptions serverOptions = new BaseServerOptions (config );
112+ List <CountDownLatch > pending = new ArrayList <>();
113+
114+ EventName healthCheck = new EventName ("healthcheck" );
115+ bus .addListener (
116+ new EventListener <>(
117+ healthCheck ,
118+ Object .class ,
119+ obj -> {
120+ synchronized (pending ) {
121+ // Concurrent health checks might influence each other, we can ignore this.
122+ // We only want to see any event is delivered to tell the bus is healthy.
123+ pending .removeIf (
124+ latch -> {
125+ latch .countDown ();
126+ return true ;
127+ });
128+ }
129+ }));
110130
111131 return new NettyServer (
112132 serverOptions ,
@@ -117,10 +137,10 @@ public Server<?> asServer(Config initialConfig) {
117137 req -> {
118138 CountDownLatch latch = new CountDownLatch (1 );
119139
120- EventName healthCheck = new EventName ( "healthcheck" );
121- bus . addListener (
122- new EventListener <>(
123- healthCheck , Object . class , obj -> latch . countDown ()));
140+ synchronized ( pending ) {
141+ pending . add ( latch );
142+ }
143+
124144 bus .fire (new Event (healthCheck , "ping" ));
125145
126146 try {
You can’t perform that action at this time.
0 commit comments