Skip to content

Add GlitchesMonitor#518

Merged
gjcairo merged 10 commits intoapple:mainfrom
gjcairo:max-stream-glitches
Jul 16, 2025
Merged

Add GlitchesMonitor#518
gjcairo merged 10 commits intoapple:mainfrom
gjcairo:max-stream-glitches

Conversation

@gjcairo
Copy link
Contributor

@gjcairo gjcairo commented Jun 29, 2025

Add a GlitchesMonitor that will terminate a connection if too many stream resets are triggered.

@gjcairo gjcairo force-pushed the max-stream-glitches branch 2 times, most recently from ce2a335 to a8f05bc Compare June 30, 2025 10:40
@gjcairo gjcairo added the 🆕 semver/minor Adds new public API. label Jun 30, 2025
@gjcairo gjcairo marked this pull request as ready for review June 30, 2025 11:39
@glbrntt glbrntt requested a review from Lukasa June 30, 2025 13:29
@gjcairo gjcairo requested a review from glbrntt July 3, 2025 09:22
@gjcairo gjcairo force-pushed the max-stream-glitches branch from 6b28a73 to 27a5ef5 Compare July 3, 2025 09:48
@gjcairo
Copy link
Contributor Author

gjcairo commented Jul 3, 2025

The failing allocation test seems to be a regression elsewhere in NIO (see #519)

//
//===----------------------------------------------------------------------===//

package struct GlitchesMonitor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure package visibility is a good idea here? It enables release mode unit tests, sure, but it also causes the optimizer to generate suboptimal code. Given that swift-nio-http2 uses @testable import extensively already, I don't think we gain much by avoiding it here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It enables release mode unit tests, sure, but it also causes the optimizer to generate suboptimal code.

Can you expand on why it's suboptimal? Also, should internal + @testable generally be preferred for tests or only in http2 where it's already pervasive?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's suboptimal because it inhibits some optimizations that the compiler can make by virtue of being able to observe all usage sites. An internal symbol or type, except when compiled with -enable-testability, has all usage sites visible in the code. This can allow strong effects to be inferred, some types to be deleted, etc.

package visibility doesn't do that: it's essentially the same visibility as -enable-testability would trigger, but all the time. Its saving grace is that it works equivalently well in both modes.

I think package should be preferred in contexts where running the unit tests in release mode is meaningful. I personally don't care much about those, but users who do should go for it. Otherwise, I'd recommend sticking with @testable import.

public var maximumBufferedControlFrames: Int = 10000
public var maximumSequentialContinuationFrames: Int = NIOHTTP2Handler.defaultMaximumSequentialContinuationFrames
public var maximumRecentlyResetStreams: Int = NIOHTTP2Handler.defaultMaximumRecentlyResetFrames
public var maximumConnectionGlitches: Int = GlitchesMonitor.defaultMaximumGlitches
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good, I think, to include narrative docs that explain this field and what it does.

}
}

/// The remote peer has triggered too many stream errors on this connection.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might broaden the definition here in future, so let's just call it glitches instead of stream errors.

@gjcairo gjcairo requested a review from Lukasa July 14, 2025 19:50
@gjcairo gjcairo force-pushed the max-stream-glitches branch from 3837864 to db92ada Compare July 15, 2025 16:31
@gjcairo gjcairo merged commit f0e9452 into apple:main Jul 16, 2025
40 checks passed
@gjcairo gjcairo deleted the max-stream-glitches branch July 16, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants