do not remove the uds socket on pause (#442)

* do not remove the uds socket on pause

* fmt

* revert the delete

* changelog

* add regression test

* add regression test

---------

Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
This commit is contained in:
Jean Bouchard 2026-02-08 01:32:10 -05:00 committed by GitHub
parent 2c401e08e4
commit 22f98ec136
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 12 deletions

View File

@ -4,6 +4,9 @@
- Minimum supported Rust version (MSRV) is now 1.88.
- internal: Use `core::future::{ready, Ready}` instead of actix-utils'
- actix-server no longer removes the uds socket [#442]
[#442]: https://github.com/actix/actix-net/pull/442
## 2.6.0

View File

@ -31,7 +31,7 @@ async fn run() -> io::Result<()> {
let count = Arc::new(AtomicUsize::new(0));
let addr = ("127.0.0.1", 8080);
tracing::info!("starting server on port: {}", &addr.0);
tracing::info!("starting server on: {}:{}", &addr.0, &addr.1);
// Bind socket address and start worker(s). By default, the server uses the number of physical
// CPU cores as the worker count. For this reason, the closure passed to bind needs to return

View File

@ -74,17 +74,7 @@ impl Source for MioListener {
match *self {
MioListener::Tcp(ref mut lst) => lst.deregister(registry),
#[cfg(unix)]
MioListener::Uds(ref mut lst) => {
let res = lst.deregister(registry);
// cleanup file path
if let Ok(addr) = lst.local_addr() {
if let Some(path) = addr.as_pathname() {
let _ = std::fs::remove_file(path);
}
}
res
}
MioListener::Uds(ref mut lst) => lst.deregister(registry),
}
}
}
@ -291,4 +281,33 @@ mod tests {
assert!(format!("{lst}").contains("/tmp/sock.xxxxx"));
}
}
#[test]
#[cfg(unix)]
fn uds_deregister_does_not_unlink_socket_file() {
use std::sync::atomic::{AtomicUsize, Ordering};
static CNT: AtomicUsize = AtomicUsize::new(0);
let name = format!(
"actix-server-test-uds-{}-{}.sock",
std::process::id(),
CNT.fetch_add(1, Ordering::Relaxed)
);
let path = std::env::temp_dir().join(name);
let _ = std::fs::remove_file(&path);
let mut lst = MioListener::Uds(MioUnixListener::bind(&path).unwrap());
assert!(path.exists());
let poll = mio::Poll::new().unwrap();
poll.registry()
.register(&mut lst, mio::Token(0), mio::Interest::READABLE)
.unwrap();
poll.registry().deregister(&mut lst).unwrap();
// Regression test for https://github.com/actix/actix-net/issues/364.
assert!(path.exists());
}
}