Skip to content

Commit 9ea2497

Browse files
committed
fix(serial): remove blocking tcdrain from Drop impl
The Drop impl on SerialInner called tcdrain(), a blocking syscall that waits for all queued output to be transmitted. If unread data sits in the kernel buffer with no reader, after a test or during shutdown, tcdrain blocks indefinitely. This hung transport::serial::tests::test_concurrent_read_write on macOS, where tcdrain on a PTY blocks forever with no reader. (On Linux, tcdrain returns immediately once the slave is closed, masking the bug.) Removing the Drop impl is safe for real hardware. write() copies data into the kernel's output buffer; once it returns, the data is in kernel space. The tty close path drains pending output for USB serial devices (controlled by the driver's closing_wait parameter, default 30 seconds). The tcdrain in Drop was redundant with what close() already provides for real devices. Fixes: #46
1 parent 7942a3d commit 9ea2497

1 file changed

Lines changed: 1 addition & 12 deletions

File tree

mujina-miner/src/transport/serial.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::time::Duration;
2828
use futures::ready;
2929
use parking_lot::RwLock;
3030
use rustix::fs::{Mode, OFlags, open};
31-
use rustix::termios::{ControlModes, tcdrain, tcgetattr, tcsetattr};
31+
use rustix::termios::{ControlModes, tcgetattr, tcsetattr};
3232
use tokio::io::unix::AsyncFd;
3333
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
3434

@@ -519,17 +519,6 @@ impl SerialControl {
519519
}
520520
}
521521

522-
impl Drop for SerialInner {
523-
fn drop(&mut self) {
524-
// Note: AsyncFd automatically closes the file descriptor
525-
// But we should drain pending output data first
526-
let fd = self.fd.as_raw_fd();
527-
528-
// Best effort drain - ignore errors on drop
529-
let _ = tcdrain(unsafe { BorrowedFd::borrow_raw(fd) });
530-
}
531-
}
532-
533522
#[cfg(test)]
534523
mod tests {
535524
use super::*;

0 commit comments

Comments
 (0)