fix(sdk): tolerate closed tunnel writers - #1099
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe Node and Python SDKs centralize stream cleanup. Their ChangesSDK shutdown handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
1108ec7 to
fe56bad
Compare
📦 BoxLite review — looks good ·
|
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 `@sdks/node/src/network.rs`:
- Around line 126-134: Document both public close contracts: in
sdks/node/src/network.rs:126-134, update the public close API documentation to
state that NotConnected is treated as successful while other shutdown errors
fail; in sdks/python/src/network.rs:156-164, document the same shutdown behavior
and that reader cleanup completes successfully.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fec5af33-df29-47d6-934c-18af2a1fb9fa
📒 Files selected for processing (2)
sdks/node/src/network.rssdks/python/src/network.rs
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 `@sdks/python/src/network.rs`:
- Around line 21-27: Update the shutdown flow around stream.shutdown().await to
store its result instead of returning immediately for non-NotConnected errors,
always execute reader.lock().await.take() after the writer is removed, then
return the stored shutdown result while preserving the existing NotConnected
handling.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2a1294cf-a8d0-4be2-9288-e4d13473283f
📒 Files selected for processing (2)
sdks/node/src/network.rssdks/python/src/network.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- sdks/node/src/network.rs
| let mut writer = writer.lock().await; | ||
| if let Some(mut stream) = writer.take() { | ||
| match stream.shutdown().await { | ||
| Ok(()) => {} | ||
| Err(error) if error.kind() == std::io::ErrorKind::NotConnected => {} | ||
| Err(error) => return Err(error), | ||
| } | ||
| } | ||
| reader.lock().await.take(); | ||
| Ok(()) |
There was a problem hiding this comment.
🛑 Node close_streams leaks reader on shutdown error
return Err(error) at line 24 exits before reader.lock().await.take() at line 27 runs, so a non-NotConnected shutdown error leaves the reader un-cleared, unlike python's just-fixed version (a3e637d) of the identical function
| let mut writer = writer.lock().await; | |
| if let Some(mut stream) = writer.take() { | |
| match stream.shutdown().await { | |
| Ok(()) => {} | |
| Err(error) if error.kind() == std::io::ErrorKind::NotConnected => {} | |
| Err(error) => return Err(error), | |
| } | |
| } | |
| reader.lock().await.take(); | |
| Ok(()) | |
| async fn close_streams( | |
| reader: &tokio::sync::Mutex<Option<ConnectionReader>>, | |
| writer: &tokio::sync::Mutex<Option<ConnectionWriter>>, | |
| ) -> std::io::Result<()> { | |
| let mut writer = writer.lock().await; | |
| let shutdown_result = if let Some(mut stream) = writer.take() { | |
| match stream.shutdown().await { | |
| Ok(()) => Ok(()), | |
| Err(error) if error.kind() == std::io::ErrorKind::NotConnected => Ok(()), | |
| Err(error) => Err(error), | |
| } | |
| } else { | |
| Ok(()) | |
| }; | |
| reader.lock().await.take(); | |
| shutdown_result | |
| } |
Treat an already disconnected tunnel writer as successfully closed in the Python and Node SDKs.
Test plan:
Summary by CodeRabbit