mirror of
https://github.com/apple/swift-nio-http2
synced 2026-11-28 05:14:25 +00:00
Remove flushability of streams when stream window size is set to zero. (#55)
Motivation: When setting the stream window size for a stream which had data but couldn't write it (because of a zero window size) the stream would be marked as flushable. Setting the window size to zero again would not mark it as unflushable. On the following window (non-zero) resize it would be marked as flushable again. However, since this is preceeded by an assertion that it wasn't already marked as flushable it would cause a crash. Modifications: - Mark the stream as unflushable if it previously had data which it couldn't write. Result: Fewer crashes
This commit is contained in:
1 parent
4a490f2e04
commit
2bec00f11c
3 files changed
+29
No files matched your search
@@ -103,6 +103,9 @@ internal struct OutboundFlowControlBuffer {
|
||||
if $0.hasPendingData && !hadData {
|
||||
assert(!self.flushableStreams.contains($0.streamID))
|
||||
self.flushableStreams.insert($0.streamID)
|
||||
} else if !$0.hasPendingData && hadData {
|
||||
assert(self.flushableStreams.contains($0.streamID))
|
||||
self.flushableStreams.remove($0.streamID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ extension OutboundFlowControlBufferTests {
|
||||
("testWritesForUnknownStreamsFail", testWritesForUnknownStreamsFail),
|
||||
("testOverlargeFramesAreSplitOnMaxFrameSizeByteBuffer", testOverlargeFramesAreSplitOnMaxFrameSizeByteBuffer),
|
||||
("testOverlargeFramesAreSplitOnMaxFrameSizeFileRegion", testOverlargeFramesAreSplitOnMaxFrameSizeFileRegion),
|
||||
("testChangingStreamWindowSizeToZeroAndBack", testChangingStreamWindowSizeToZeroAndBack),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,6 +312,31 @@ class OutboundFlowControlBufferTests: XCTestCase {
|
||||
self.buffer.updateWindowOfStream(streamOne, newSize: 20)
|
||||
self.receivedFrames().assertFramesMatch([dataFrame], dataFileRegionToByteBuffer: false)
|
||||
}
|
||||
|
||||
func testChangingStreamWindowSizeToZeroAndBack() {
|
||||
// This test checks that updating the window size to zero on a flushable stream makes it no longer flushable.
|
||||
let streamOne = HTTP2StreamID(1)
|
||||
self.buffer.streamCreated(streamOne, initialWindowSize: 0)
|
||||
|
||||
let dataFrame = self.createDataFrame(streamOne, byteBufferSize: 15)
|
||||
XCTAssertNoThrow(try self.buffer.processOutboundFrame(dataFrame, promise: nil).assertNothing())
|
||||
XCTAssertEqual(0, self.receivedFrames().count)
|
||||
|
||||
// The stream has data to write but the window size is zero, so it won't write.
|
||||
self.buffer.flushReceived()
|
||||
|
||||
self.buffer.updateWindowOfStream(streamOne, newSize: 15)
|
||||
self.buffer.updateWindowOfStream(streamOne, newSize: 0)
|
||||
|
||||
// Check the stream has been marked unflushable.
|
||||
self.buffer.flushReceived()
|
||||
XCTAssertEqual(0, self.receivedFrames().count)
|
||||
|
||||
self.buffer.updateWindowOfStream(streamOne, newSize: 15)
|
||||
self.buffer.flushReceived()
|
||||
|
||||
self.receivedFrames().assertFramesMatch([dataFrame], dataFileRegionToByteBuffer: false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user