socket length fixes#317
Conversation
| // Another process may have the socket - try removing again and retry | ||
| warn!("Socket address in use, attempting cleanup and retry: {}", self.socket_path); | ||
| let _ = std::fs::remove_file(path); | ||
| std::thread::sleep(std::time::Duration::from_millis(100)); |
There was a problem hiding this comment.
🟡 Blocking std::thread::sleep used in async context
The retry logic for socket binding uses std::thread::sleep in an async function, which blocks the tokio runtime's worker thread.
Click to expand
Issue Details
In relay-pty/src/socket.rs:100, the code uses std::thread::sleep(std::time::Duration::from_millis(100)) inside the async fn run() method:
Err(e) if e.kind() == std::io::ErrorKind::AddrInUse => {
warn!("Socket address in use, attempting cleanup and retry: {}", self.socket_path);
let _ = std::fs::remove_file(path);
std::thread::sleep(std::time::Duration::from_millis(100)); // Blocks tokio worker!
UnixListener::bind(&self.socket_path)
.context(format!("Failed to bind socket at {} (after retry)", self.socket_path))?
}This function is spawned via tokio::spawn in main.rs:310, meaning std::thread::sleep will block the tokio worker thread instead of yielding to other tasks.
Impact
During the 100ms sleep, other async tasks scheduled on the same worker thread will be blocked. Since this only occurs during startup in the rare EADDRINUSE retry path, the practical impact is minimal.
Expected Behavior
Use tokio::time::sleep(Duration::from_millis(100)).await for non-blocking sleep in async context.
Recommendation: Replace std::thread::sleep(std::time::Duration::from_millis(100)) with tokio::time::sleep(std::time::Duration::from_millis(100)).await
Was this helpful? React with 👍 or 👎 to provide feedback.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Uh oh!
There was an error while loading. Please reload this page.