From 5e678b11e9150f2f9728b1641e36f16ec7c8c3ef Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 10 Jan 2018 12:16:34 +0100 Subject: net: Fix a race condition. - Previously, the TcpListener 'l' that is handed to the child process via conversion to a raw filedescriptor was closed when being dropped. This lead to a small chance of closing the next TcpListener, resulting in spurious failures when falling back to the in-process server. --- net/src/ipc.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'net') diff --git a/net/src/ipc.rs b/net/src/ipc.rs index c67b049b..fef222ad 100644 --- a/net/src/ipc.rs +++ b/net/src/ipc.rs @@ -183,8 +183,14 @@ impl Descriptor { } fn fork(&self, l: TcpListener) -> io::Result<()> { + // Convert to raw fd, then forget l so that it will not be + // closed when it is dropped. + let fd = l.as_raw_fd(); + ::std::mem::forget(l); + Command::new(&self.executable.clone().into_os_string()) - .stdin(unsafe { Stdio::from_raw_fd(l.as_raw_fd()) }) + // l will be closed here if the exec fails. + .stdin(unsafe { Stdio::from_raw_fd(fd) }) .spawn()?; Ok(()) } -- cgit v1.2.3