Skip to content

Commit

Permalink
Fix FindBugs warnings. activeRemoteStreamCount wasn't thread safe.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1687346 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jun 24, 2015
1 parent 0cc544a commit 74ed117
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions java/org/apache/coyote/http2/Http2UpgradeHandler.java
Expand Up @@ -117,7 +117,7 @@ public class Http2UpgradeHandler extends AbstractStream implements InternalHttpU
private long writeTimeout = 10000; private long writeTimeout = 10000;


private final Map<Integer,Stream> streams = new HashMap<>(); private final Map<Integer,Stream> streams = new HashMap<>();
private volatile int activeRemoteStreamCount = 0; private final AtomicInteger activeRemoteStreamCount = new AtomicInteger(0);
private volatile int maxRemoteStreamId = 0; private volatile int maxRemoteStreamId = 0;
// Start at -1 so the 'add 2' logic in closeIdleStreams() works // Start at -1 so the 'add 2' logic in closeIdleStreams() works
private volatile int maxActiveRemoteStreamId = -1; private volatile int maxActiveRemoteStreamId = -1;
Expand All @@ -144,7 +144,7 @@ public Http2UpgradeHandler(Adapter adapter, Request coyoteRequest) {
streams.put(key, stream); streams.put(key, stream);
maxRemoteStreamId = 1; maxRemoteStreamId = 1;
maxActiveRemoteStreamId = 1; maxActiveRemoteStreamId = 1;
activeRemoteStreamCount = 1; activeRemoteStreamCount.set(1);
maxProcessedStreamId = 1; maxProcessedStreamId = 1;
} }
} }
Expand Down Expand Up @@ -449,7 +449,7 @@ void writeBody(Stream stream, ByteBuffer data, int len, boolean finished) throws
header[4] = FLAG_END_OF_STREAM; header[4] = FLAG_END_OF_STREAM;
stream.sentEndOfStream(); stream.sentEndOfStream();
if (!stream.isActive()) { if (!stream.isActive()) {
activeRemoteStreamCount--; activeRemoteStreamCount.decrementAndGet();
} }
} }
ByteUtil.set31Bits(header, 5, stream.getIdentifier().intValue()); ByteUtil.set31Bits(header, 5, stream.getIdentifier().intValue());
Expand Down Expand Up @@ -788,7 +788,7 @@ public void receiveEndOfStream(int streamId) throws ConnectionException {
Stream stream = getStream(streamId, true); Stream stream = getStream(streamId, true);
stream.receivedEndOfStream(); stream.receivedEndOfStream();
if (!stream.isActive()) { if (!stream.isActive()) {
activeRemoteStreamCount--; activeRemoteStreamCount.decrementAndGet();
} }
} }


Expand All @@ -811,9 +811,8 @@ public HeaderEmitter headersStart(int streamId) throws Http2Exception {
stream.checkState(FrameType.HEADERS); stream.checkState(FrameType.HEADERS);
stream.receivedStartOfHeaders(); stream.receivedStartOfHeaders();
closeIdleStreams(streamId); closeIdleStreams(streamId);
if (localSettings.getMaxConcurrentStreams() > activeRemoteStreamCount) { if (localSettings.getMaxConcurrentStreams() > activeRemoteStreamCount.incrementAndGet()) {
activeRemoteStreamCount++; activeRemoteStreamCount.decrementAndGet();
} else {
throw new StreamException(sm.getString("upgradeHandler.tooManyRemoteStreams", throw new StreamException(sm.getString("upgradeHandler.tooManyRemoteStreams",
Long.toString(localSettings.getMaxConcurrentStreams())), Long.toString(localSettings.getMaxConcurrentStreams())),
Http2Error.REFUSED_STREAM, streamId); Http2Error.REFUSED_STREAM, streamId);
Expand Down

0 comments on commit 74ed117

Please sign in to comment.