fix(sftp): close persistent SFTP channel on page dispose and guard async race#1173
Conversation
…ync race - Close _status.client in dispose() to prevent channel leak when navigating away from the SFTP browser page. - Replace ??= with explicit null check to avoid concurrent double-open race when multiple _listDir calls overlap. - Add catch block to close and null-out stale client on non-SftpStatusError, allowing recovery on next call.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSftpPage adds an Possibly related PRs
Suggested reviewers
🚥 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)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/view/page/storage/sftp.dart`:
- Around line 1038-1043: The code can race when initializing _status.client in
_listDirWithFallback: multiple callers may see _status.client == null and each
call _withSftpOpTimeout(_client.sftp()), creating duplicate sessions; introduce
a single-flight guard (e.g. a private Future<SftpClient>? _openingClientFuture)
that is checked/awaited before starting a new open, assign the resulting client
to _status.client once completed, and clear/reset the guard on success or error;
update the existing initialization logic that calls _withSftpOpTimeout('open
browser session', _client.sftp()) to use this shared in-flight future so only
one _client.sftp() is invoked concurrently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: da3d3c1d-d977-4cd0-b842-9a2111f4f064
📒 Files selected for processing (1)
lib/view/page/storage/sftp.dart
- Introduce _openingClientFuture to prevent multiple concurrent _client.sftp() calls when rapid navigation races the lazy _status.client initialisation. - Reset _openingClientFuture on dispose and after errors. - Add mounted check after awaiting the future so unmounted pages do not attempt further UI operations.
Summary by CodeRabbit