Skip to content

Commit

Permalink
Merge pull request square#1106 from square/jwilson_1026_fix_concurrency
Browse files Browse the repository at this point in the history
Don't hold the connection lock when calling receiveRstStream.
  • Loading branch information
JakeWharton committed Oct 26, 2014
2 parents c079c9e + 8f1bc30 commit 59b11fb
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -734,18 +733,19 @@ private void ackSettingsLater(final Settings peerSettings) {
@Override public void goAway(int lastGoodStreamId, ErrorCode errorCode, ByteString debugData) {
if (debugData.size() > 0) { // TODO: log the debugData
}

// Copy the streams first. We don't want to hold a lock when we call receiveRstStream().
SpdyStream[] streamsCopy;
synchronized (SpdyConnection.this) {
streamsCopy = streams.values().toArray(new SpdyStream[streams.size()]);
shutdown = true;
}

// Fail all streams created after the last good stream ID.
for (Iterator<Map.Entry<Integer, SpdyStream>> i = streams.entrySet().iterator();
i.hasNext(); ) {
Map.Entry<Integer, SpdyStream> entry = i.next();
int streamId = entry.getKey();
if (streamId > lastGoodStreamId && entry.getValue().isLocallyInitiated()) {
entry.getValue().receiveRstStream(ErrorCode.REFUSED_STREAM);
i.remove();
}
// Fail all streams created after the last good stream ID.
for (SpdyStream spdyStream : streamsCopy) {
if (spdyStream.getId() > lastGoodStreamId && spdyStream.isLocallyInitiated()) {
spdyStream.receiveRstStream(ErrorCode.REFUSED_STREAM);
removeStream(spdyStream.getId());
}
}
}
Expand Down

0 comments on commit 59b11fb

Please sign in to comment.