Conversation
📝 WalkthroughWalkthroughUse overflow-safe addition when computing TCP_USER_TIMEOUT: Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
…_VALUE idle timeout Co-authored-by: Isaac
…idle timeouts When idleTimeoutMillis is near Long.MAX_VALUE, the addition of TCP_USER_TIMEOUT_BUFFER_MILLIS (5000) overflowed the long type, producing a negative value that Linux rejects with EINVAL. Clamp idleTimeoutMillis before addition so the sum saturates at Long.MAX_VALUE instead of wrapping. Ints.saturatedCast then correctly yields Integer.MAX_VALUE (~24.8 day timeout).
8928e3e to
b1780e5
Compare
…T calculation Replace manual Math.min clamp with Guava's LongMath.saturatedAdd, which is already used throughout the codebase for the same pattern. Remove redundant test comment. Co-authored-by: Isaac
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6711 +/- ##
============================================
- Coverage 74.46% 74.00% -0.46%
- Complexity 22234 24118 +1884
============================================
Files 1963 2176 +213
Lines 82437 90501 +8064
Branches 10764 11859 +1095
============================================
+ Hits 61385 66975 +5590
- Misses 15918 17906 +1988
- Partials 5134 5620 +486 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Motivation:
ChannelUtil.applyDefaultChannelOptions()overflows whenidleTimeoutMillisis nearLong.MAX_VALUE. The expressionidleTimeoutMillis + TCP_USER_TIMEOUT_BUFFER_MILLIS(where the buffer is 5,000)wraps the
longtype to a large negative number, andInts.saturatedCast()then clamps it toInteger.MIN_VALUE(-2,147,483,648).Linux rejects this negative value for
TCP_USER_TIMEOUTviasetsockopt()withEINVAL. Starting with Netty 4.1.131+, channel option values are validated at set time and throw exceptionsinstead of being silently logged internally (see netty/netty#15896). This means the overflow now causes a hard failure rather than a silent misconfiguration.
Modifications:
LongMath.saturatedAddto prevent thelongoverflow before passing the result toInts.saturatedCast:Result: