-
Notifications
You must be signed in to change notification settings - Fork 104
fix: prevent IdleTimeout from closing control connection during activ… #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…e data transfers Before this change, the server would immediately close control connections when IdleTimeout was reached, regardless of whether a data transfer was active. This caused issues with large or slow file transfers that could take longer than the configured idle timeout. Now the server checks if there is an active data transfer (isTransferOpen) before closing the connection. If a transfer is active, it extends the deadline instead of closing the connection, allowing the transfer to complete. Fixes #430 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Florent Clairambault <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #577 +/- ##
==========================================
- Coverage 86.74% 86.40% -0.35%
==========================================
Files 12 12
Lines 2369 2383 +14
==========================================
+ Hits 2055 2059 +4
- Misses 238 247 +9
- Partials 76 77 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code Review for PR #577SummaryThis PR addresses issue #430 by preventing the control connection from being closed due to idle timeout when there's an active data transfer in progress. The solution is straightforward and correctly identifies active transfers before deciding whether to close the connection. ✅ Strengths
🔍 Issues and Recommendations1. Potential Infinite Loop Risk 🚨The current implementation extends the deadline by IdleTimeout seconds each time. If a transfer stalls (e.g., network issues, client hanging), this could keep the connection alive indefinitely. Recommendation: Consider adding a maximum transfer timeout or counter to prevent infinite extensions: // Add a field to track consecutive extensions
if hasActiveTransfer {
if c.transferTimeoutExtensions >= maxTransferExtensions {
// Force close after too many extensions
c.logger.Warn("Transfer timeout exceeded maximum extensions")
// Continue with normal timeout handling
} else {
c.transferTimeoutExtensions++
// Extend deadline...
}
} 2. Missing Test Coverage
|
Code Review for PR #577: Fix IdleTimeout during active transfersThank you for this fix! I've reviewed the changes and have the following feedback: ✅ Strengths
🔍 Areas for Improvement1. Deadline Extension LogicThe current implementation has a potential issue with the deadline extension calculation: extendedDeadline := time.Now().Add(time.Duration(time.Second.Nanoseconds() * int64(c.server.settings.IdleTimeout))) Issues:
2. Missing Test CoverageThe PR doesn't include tests for this new behavior. Consider adding a test case that:
Example test structure: func TestIdleTimeoutWithActiveTransfer(t *testing.T) {
// Create server with 2-second idle timeout
// Start a file transfer
// Sleep for 3 seconds (> idle timeout)
// Verify connection is still alive
// Complete transfer
// Wait for idle timeout
// Verify connection closes
} 3. Potential Race ConditionWhile the mutex protects 4. Consider Alternative ApproachesInstead of repeatedly extending on timeout, consider:
📝 Suggested ImplementationHere's a more robust approach: if hasActiveTransfer {
// Extend by a reasonable period (e.g., 5 minutes or 10x idle timeout)
extensionPeriod := time.Duration(c.server.settings.IdleTimeout) * time.Second * 10
if extensionPeriod < 5*time.Minute {
extensionPeriod = 5 * time.Minute
}
if errSet := c.conn.SetDeadline(time.Now().Add(extensionPeriod)); errSet != nil {
c.logger.Error("Could not extend deadline during transfer", "err", errSet)
// Consider whether to continue or close the connection here
}
if c.debug {
c.logger.Debug("Extended deadline due to active transfer",
"extension", extensionPeriod)
}
return
} 🚀 Overall AssessmentThis is a good fix for an important issue. With the suggested improvements to the deadline calculation and added test coverage, this will be a solid addition to the codebase. The fix aligns well with the library's architecture and maintains backward compatibility. |
Code Review for PR #577I've reviewed the changes to fix the IdleTimeout issue during active data transfers. Here's my feedback: ✅ Positive Aspects
|
Pull Request Review: Fix IdleTimeout During Active TransfersThank you for addressing issue #430! This is an important fix for handling large or slow file transfers. Positive Aspects
Issues and Concerns1. Logic Flow Problem (client_handler.go:479-493)After the new code block that extends the deadline and returns early, the original timeout handling code still executes when there's NO active transfer. This code path extends the deadline by 1 minute (line 480-481) but then immediately logs timeout and notifies the client (line 484-491). Why extend the deadline only to immediately close the connection? This seems like a legacy quirk - the 1-minute extension appears necessary only to allow the error message to be sent. 2. Inconsistent Deadline CalculationThe new code uses: time.Duration(time.Second.Nanoseconds() * int64(c.server.settings.IdleTimeout)) Recommendation: Consider extracting a helper method to make this consistent and clearer. 3. Potential Race Condition WindowThere's a brief window between checking isTransferOpen and extending the deadline where the transfer could complete. While unlikely to cause issues in practice, the worst case is an extra deadline extension which is benign. 4. Missing Test CoverageThe existing TestIdleTimeout (handle_misc_test.go:44) doesn't cover the new behavior. A test case should verify that the control connection remains open during active data transfers that exceed IdleTimeout. Suggested Improvements
Security ConsiderationsPotential DoS Vector: A malicious client could keep a data connection open indefinitely to bypass idle timeout. However, this is mitigated by the ConnectionTimeout setting for data connections, and existing behavior already allows this via legitimate slow transfers. No new security concerns are introduced. VerdictConditionally Approve - The fix correctly addresses the reported issue and is safe to merge for fixing the immediate problem. The suggested improvements would enhance maintainability and test coverage. Review generated with assistance from Claude Code |
…e data transfers
Before this change, the server would immediately close control connections when IdleTimeout was reached, regardless of whether a data transfer was active. This caused issues with large or slow file transfers that could take longer than the configured idle timeout.
Now the server checks if there is an active data transfer (isTransferOpen) before closing the connection. If a transfer is active, it extends the deadline instead of closing the connection, allowing the transfer to complete.
Fixes #430
🤖 Generated with Claude Code