Skip to content

Commit 8e06aa8

Browse files
committed
Updates a TCP server traffic shaping config can observe an incorrect server state.
Motivation: TCP server traffic shaping update reads the traffic shaping handler to reconfigure it but does it in a racy fashion. Changes: Make the server traffic shaping handler volatile.
1 parent 1dae6b5 commit 8e06aa8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/java/io/vertx/core/net/impl/TCPServerBase.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public abstract class TCPServerBase implements Closeable, MetricsProvider {
6565
// Main
6666
private SSLHelper sslHelper;
6767
private volatile Future<SslContextUpdate> sslChannelProvider;
68-
private GlobalTrafficShapingHandler trafficShapingHandler;
68+
private volatile GlobalTrafficShapingHandler trafficShapingHandler;
6969
private ServerChannelLoadBalancer channelBalancer;
7070
private Future<Channel> bindFuture;
7171
private TCPMetrics<?> metrics;
@@ -153,7 +153,8 @@ public void updateTrafficShapingOptions(TrafficShapingOptions options) {
153153
if (server != null && server != this) {
154154
server.updateTrafficShapingOptions(options);
155155
} else {
156-
if (trafficShapingHandler == null) {
156+
GlobalTrafficShapingHandler handler = trafficShapingHandler;
157+
if (handler == null) {
157158
throw new IllegalStateException("Unable to update traffic shaping options because the server was not configured " +
158159
"to use traffic shaping during startup");
159160
}
@@ -162,14 +163,14 @@ public void updateTrafficShapingOptions(TrafficShapingOptions options) {
162163
if(!options.equals(server.options.getTrafficShapingOptions())) {
163164
server.options.setTrafficShapingOptions(options);
164165
long checkIntervalForStatsInMillis = options.getCheckIntervalForStatsTimeUnit().toMillis(options.getCheckIntervalForStats());
165-
trafficShapingHandler.configure(options.getOutboundGlobalBandwidth(), options.getInboundGlobalBandwidth(), checkIntervalForStatsInMillis);
166+
handler.configure(options.getOutboundGlobalBandwidth(), options.getInboundGlobalBandwidth(), checkIntervalForStatsInMillis);
166167

167168
if (options.getPeakOutboundGlobalBandwidth() != 0) {
168-
trafficShapingHandler.setMaxGlobalWriteSize(options.getPeakOutboundGlobalBandwidth());
169+
handler.setMaxGlobalWriteSize(options.getPeakOutboundGlobalBandwidth());
169170
}
170171
if (options.getMaxDelayToWait() != 0) {
171172
long maxDelayToWaitInMillis = options.getMaxDelayToWaitTimeUnit().toMillis(options.getMaxDelayToWait());
172-
trafficShapingHandler.setMaxWriteDelay(maxDelayToWaitInMillis);
173+
handler.setMaxWriteDelay(maxDelayToWaitInMillis);
173174
}
174175
} else {
175176
log.debug("Not updating traffic shaping options as they have not changed");

0 commit comments

Comments
 (0)