-
Notifications
You must be signed in to change notification settings - Fork 98
Properly remove Session from the list when it terminates spontaneously #6637
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
Conversation
When UDP-based Session goes idle or is closed by the other side, it should be correctly removed from the Session list. Also added some cosmetic code improvements.
📝 Walkthrough📝 WalkthroughWalkthroughThe changes in this pull request involve modifications across three main files: Changes
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (3)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (5)
common/network-types/src/udp.rs (1)
304-305
: Consider implementing socket splittingThe TODO comment suggests an important architectural improvement that could enhance socket management and reusability.
Would you like me to help design and implement the socket splitting functionality? I can create a GitHub issue to track this enhancement.
transport/session/src/manager.rs (2)
Line range hint
359-419
: Consider enhancing error handling and race condition protection in session initiationThe session initiation logic could benefit from the following improvements:
- Add more granular error handling for different failure scenarios (network issues, protocol mismatches, etc.)
- Consider adding a mutex or similar synchronization primitive around session establishment to prevent potential race conditions when multiple sessions are being established simultaneously
pub async fn new_session(&self, cfg: SessionClientConfig) -> crate::errors::Result<Session> { + // Add a mutex guard here to prevent race conditions + let _guard = self.session_establishment_lock.lock().await; + let msg_sender = self.msg_sender.get().ok_or(SessionManagerError::NotStarted)?; let (tx_initiation_done, rx_initiation_done) = futures::channel::mpsc::unbounded(); @@ -419,6 +422,15 @@ Either::Left((Err(e)), _) => { - error!(challenge = e.challenge, error = ?e, "the other party rejected the session initiation with error"); - Err(TransportSessionError::Rejected(e.reason)) + match e.reason { + StartErrorReason::NoSlotsAvailable => { + error!(challenge = e.challenge, "no slots available for session"); + Err(TransportSessionError::NoSlots) + } + StartErrorReason::ProtocolMismatch => { + error!(challenge = e.challenge, "protocol version mismatch"); + Err(TransportSessionError::ProtocolMismatch) + } + _ => Err(TransportSessionError::Rejected(e.reason)) + } }
519-519
: Improve session logging consistency and metadataThe session logging could be enhanced by:
- Using structured logging with consistent fields across all log messages
- Including additional session metadata (e.g., protocol, capabilities)
- Adding timing information for session establishment
-debug!(%peer, "got new session request, searching for a free session slot"); +debug!( + %peer, + protocol = ?session_req.target.protocol(), + capabilities = ?session_req.capabilities, + "got new session request, searching for a free session slot" +); -info!(%session_id, "new session established"); +info!( + %session_id, + protocol = ?session_req.target.protocol(), + capabilities = ?session_req.capabilities, + establishment_time_ms = %start_time.elapsed().as_millis(), + "new session established" +);Also applies to: 590-619
hoprd/rest-api/src/session.rs (2)
Line range hint
505-549
: Ensure consistent listener management between TCP and UDP sessions.In the UDP session handling, the listener is removed from
open_listeners
when the session closes:// Once the Session closes, remove it from the list open_listeners_clone.write().await.remove(&listener_id);However, in the TCP case, this cleanup step is missing. This could lead to inconsistent state or resource leaks. Consider adding similar cleanup logic for TCP sessions to ensure consistent management across both protocols.
Apply this diff to add the cleanup logic for TCP sessions:
state .open_listeners .write() .await .insert(ListenerId(protocol, bound_host), (target.clone(), jh)); + + // Remove the listener from the list when the task completes + let open_listeners_clone = state.open_listeners.clone(); + let listener_id = ListenerId(protocol, bound_host); + hopr_async_runtime::prelude::spawn(async move { + jh.await.unwrap_or_else(|e| error!(error = %e, "TCP listener task failed")); + open_listeners_clone.write().await.remove(&listener_id); + }); bound_host
788-791
: Standardize logging format in error handling.The logging statement has inconsistent formatting. Aligning it with the standard logging practices improves readability and consistency.
Apply this diff to standardize the logging format:
- Err(error) => error!( - session_id = ?session_id, - %error, - "error during data transfer" - ), + Err(error) => { + error!( + session_id = ?session_id, + error = %error, + "Error during data transfer" + ); + },
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
common/network-types/src/udp.rs
(17 hunks)hoprd/rest-api/src/session.rs
(7 hunks)transport/session/src/manager.rs
(6 hunks)
🧰 Additional context used
📓 Learnings (1)
hoprd/rest-api/src/session.rs (2)
Learnt from: Teebor-Choka
PR: hoprnet/hoprnet#6393
File: hoprd/rest-api/src/session.rs:91-91
Timestamp: 2024-11-12T10:55:50.205Z
Learning: The current implementation in `hoprd/rest-api/src/session.rs` assumes all sessions are TCP-like due to the missing implementation of UDP behavior. The commented-out code suggests an intention to support different session types based on `capabilities`.
Learnt from: Teebor-Choka
PR: hoprnet/hoprnet#6393
File: hoprd/rest-api/src/session.rs:91-91
Timestamp: 2024-11-12T10:56:01.095Z
Learning: The current implementation in `hoprd/rest-api/src/session.rs` assumes all sessions are TCP-like due to the missing implementation of UDP behavior. The commented-out code suggests an intention to support different session types based on `capabilities`.
🔇 Additional comments (5)
common/network-types/src/udp.rs (2)
Line range hint 267-277
: Documentation improvements look good!
The clarifications about platform-specific behavior and wildcard address handling enhance the API documentation.
437-438
: Logging improvements enhance observability!
The changes consistently improve log messages across different scenarios:
- Better error context for discarded data
- Enhanced EOF and error logging
- Improved error reporting for data dispatch and transmission
- Clear completion logging for rx/tx queues
The log levels are appropriately chosen, and the context provided will aid in debugging.
Also applies to: 459-461, 469-472, 484-487, 495-497, 521-525, 534-536, 543-546
hoprd/rest-api/src/session.rs (3)
Line range hint 443-449
: TCP socket binding and error handling are correctly implemented.
The code correctly binds the TCP socket and appropriately handles errors, ensuring that specific issues like AddrInUse
are distinctly managed.
456-457
: Added comments enhance code readability.
The new comments clearly describe the process of handling incoming TCP connections, improving the maintainability of the code.
718-718
: Logging unusable listen addresses enhances debugging.
Logging the errors when a listen address is not usable provides valuable information for troubleshooting without interrupting the binding attempts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crate version bump missing
When UDP-based Session goes idle or is closed by the other side, it should be correctly removed from the Session list.
Also added some cosmetic code improvements.