Skip to content

Commit e8ea8ba

Browse files
author
Stephanie Tilden
committed
Make DiscoveryServer stream ID global
When surfacing V2 and V3 streams alongside each other in envoy-control, DiscoveryServerCallbacks are unable to differentiate between V2 & V3 ADS upon onStreamClose(), onStreamCloseWithError(). This means that any DiscoveryServerCallback that keeps state cannot pivot on stream IDs, since there will be duplicate between V2 & V3. This change creates a global StreamCounter, which ensures stream IDs will be unique across V2 & V3 streams.
1 parent ff834cb commit e8ea8ba

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

server/src/main/java/io/envoyproxy/controlplane/server/DiscoveryServer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.Collection;
1111
import java.util.List;
1212
import java.util.concurrent.Executor;
13-
import java.util.concurrent.atomic.AtomicLong;
1413
import org.slf4j.Logger;
1514
import org.slf4j.LoggerFactory;
1615

@@ -21,7 +20,6 @@ public abstract class DiscoveryServer<T, U> {
2120
final ConfigWatcher configWatcher;
2221
final ProtoResourcesSerializer protoResourcesSerializer;
2322
private final ExecutorGroup executorGroup;
24-
private final AtomicLong streamCount = new AtomicLong();
2523

2624
/**
2725
* Creates the server.
@@ -59,7 +57,7 @@ StreamObserver<T> createRequestHandler(
5957
boolean ads,
6058
String defaultTypeUrl) {
6159

62-
long streamId = streamCount.getAndIncrement();
60+
long streamId = StreamCounter.getAndIncrement();
6361
Executor executor = executorGroup.next();
6462

6563
LOGGER.debug("[{}] open stream from {}", streamId, defaultTypeUrl);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.envoyproxy.controlplane.server;
2+
3+
import java.util.concurrent.atomic.AtomicLong;
4+
5+
public final class StreamCounter {
6+
private static final AtomicLong streamCount = new AtomicLong();
7+
8+
public static long getAndIncrement() {
9+
return streamCount.getAndIncrement();
10+
}
11+
}

0 commit comments

Comments
 (0)