Skip to content

Commit 4ab4144

Browse files
committed
do not remove the uds socket on pause
1 parent 7248131 commit 4ab4144

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

actix-server/examples/tcp-echo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async fn run() -> io::Result<()> {
3131
let count = Arc::new(AtomicUsize::new(0));
3232

3333
let addr = ("127.0.0.1", 8080);
34-
info!("starting server on port: {}", &addr.0);
34+
info!("starting server on: {}:{}", &addr.0, &addr.1);
3535

3636
// Bind socket address and start worker(s). By default, the server uses the number of physical
3737
// CPU cores as the worker count. For this reason, the closure passed to bind needs to return

actix-server/src/accept.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ impl Accept {
217217
self.deregister_all(sockets);
218218
}
219219

220+
self.terminate_all(sockets);
221+
220222
return true;
221223
}
222224

@@ -330,6 +332,10 @@ impl Accept {
330332
.for_each(|(_, info)| self.deregister_logged(info));
331333
}
332334

335+
fn terminate_all(&self, sockets: &mut[ServerSocketInfo]) {
336+
sockets.iter().for_each(|s| s.lst.terminate());
337+
}
338+
333339
// Send connection to worker and handle error.
334340
fn send_connection(&mut self, conn: Conn) -> Result<(), Conn> {
335341
let next = self.next();

actix-server/src/socket.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,28 @@ impl MioListener {
3838
match *self {
3939
MioListener::Tcp(ref lst) => lst.accept().map(|(stream, _)| MioStream::Tcp(stream)),
4040
#[cfg(unix)]
41-
MioListener::Uds(ref lst) => lst.accept().map(|(stream, _)| MioStream::Uds(stream)),
41+
MioListener::Uds(ref lst) => {
42+
lst.accept().map(|(stream, _)| MioStream::Uds(stream))
43+
}
44+
}
45+
}
46+
47+
pub(crate) fn terminate(&self) {
48+
match *self {
49+
MioListener::Tcp(_) => (),
50+
#[cfg(unix)]
51+
MioListener::Uds(ref lst) => {
52+
if let Ok(addr) = lst.local_addr() {
53+
if let Some(path) = addr.as_pathname() {
54+
let _ = std::fs::remove_file(path);
55+
}
56+
}
57+
}
4258
}
4359
}
4460
}
4561

62+
4663
impl Source for MioListener {
4764
fn register(
4865
&mut self,
@@ -74,17 +91,7 @@ impl Source for MioListener {
7491
match *self {
7592
MioListener::Tcp(ref mut lst) => lst.deregister(registry),
7693
#[cfg(unix)]
77-
MioListener::Uds(ref mut lst) => {
78-
let res = lst.deregister(registry);
79-
80-
// cleanup file path
81-
if let Ok(addr) = lst.local_addr() {
82-
if let Some(path) = addr.as_pathname() {
83-
let _ = std::fs::remove_file(path);
84-
}
85-
}
86-
res
87-
}
94+
MioListener::Uds(ref mut lst) => lst.deregister(registry)
8895
}
8996
}
9097
}
@@ -270,4 +277,17 @@ mod tests {
270277
assert!(format!("{}", lst).contains("/tmp/sock.xxxxx"));
271278
}
272279
}
280+
281+
#[test]
282+
#[cfg(unix)]
283+
fn uds_terminate() {
284+
let socket_path = std::path::Path::new("/tmp/sock.xxxx1");
285+
let _ = std::fs::remove_file(socket_path);
286+
if let Ok(socket) = MioUnixListener::bind(socket_path) {
287+
let listener = MioListener::Uds(socket);
288+
assert!(socket_path.exists());
289+
listener.terminate();
290+
assert!(!socket_path.exists());
291+
}
292+
}
273293
}

0 commit comments

Comments
 (0)