-
Notifications
You must be signed in to change notification settings - Fork 105
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 <fclairamb@users.noreply.github.com>
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. |
…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