Validate echo length; use virtual thread for ICE listener#85
Validate echo length; use virtual thread for ICE listener#85juerghegglin wants to merge 1 commit intoFAForever:masterfrom
Conversation
Two small unrelated cleanups around the ICE peer listener: 1. PeerConnectivityCheckerModule.echoReceived() previously incremented invalidEchosReceived on length != 9, then fell through to compute RTT via Longs.fromByteArray(Arrays.copyOfRange(data, offset+1, length)). When length is below 9 that throws IllegalArgumentException; when length is above 9 the first 8 bytes are reinterpreted as a timestamp and the bogus RTT poisons the EMA at line 102. Add an early return. 2. PeerIceModule started its data listener as a platform thread, missed by PR FAForever#65's virtual-thread migration (the connectivity checker, sending loop, and acceptors are all virtual). Each peer held a carrier thread on a blocking socket.receive() with no benefit. Convert to a virtual thread with a descriptive name. Both changes are zero-risk and self-contained.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR improves the ICE adapter with two independent enhancements: adding validation to reject invalid echo responses in connectivity checking, and upgrading the ICE listener thread from a platform thread to a virtual thread for better resource utilization. ChangesICE Adapter Improvements
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Two small unrelated cleanups around the ICE peer listener
1.
PeerConnectivityCheckerModule.echoReceived()— early return on bad lengthWhen an echo packet's
length != 9, the code incrementsinvalidEchosReceivedand logs a trace, but then falls through to:length < 9→Longs.fromByteArraythrowsIllegalArgumentException(it requires exactly 8 bytes).length > 9→ the first 8 bytes after the type prefix are reinterpreted as a timestamp, the resulting bogus RTT poisons the EMA at line 102, and subsequentaverageRTTreporting becomes corrupted.Adds an early
returnso invalid echoes only update the counter and don't compute an RTT.2.
PeerIceModule.startIce()— virtual thread for the data listenerPR #65 migrated this project to virtual threads (the connectivity checker, the telemetry sending loop, and the GPGNet/RPC acceptors are all
Thread.ofVirtual()). The data listener insidePeerIceModulewas missed — it still usesnew Thread(this::listener), which means every peer holds a carrier thread blocked onsocket.receive()for no benefit.Replaces with
Thread.ofVirtual().name("ice-listener-" + peer.getRemoteId()).start(this::listener)to match the surrounding code.Risk
Both changes are local and self-contained. No behavior change other than the bug fix in (1). The listener thread continues to be assigned to the same
volatile Thread listenerThreadfield and gets interrupted/joined exactly the same way on close.Verification
Local Spotless + check pass on the fix branch. No JUnit tests added in this PR — happy to follow up with one for the echo-length validation if maintainers want it (would land alongside the JUnit infrastructure I proposed in the cover note of #84).
Co-authored with Claude (Anthropic); reviewed and locally verified by me.
Summary by CodeRabbit
Release Notes
Bug Fixes
Performance