actix / actix/actix-web

Sockets and pipes open after stopping server/system

Open
#1,787 3 comments 0 reactions 0 assignees View on GitHub
A-web needs-investigation
Dominant language
Rust
Stars
24.8k
Forks
1.9k
Avg merge
23h 10m
Merged PRs (30d)
26

Description

## Expected Behavior
Stopping server/system closes all sockets and pipes.

## Current Behavior
Stopping the server/system (without exiting the process) leaves a number of sockets and pipes open.
Therefore, restarting the server increases the number of open sockets and pipes.

## Steps to Reproduce
```
use actix_web::{middleware, App, HttpServer};

pub fn main() -> std::io::Result<()> {
// - inside loop: each iteration opens 22 new pipes, 0 new sockets
// - outside loop: each iteration opens 2 new pipes, 4 new sockets
let mut system = actix_web::rt::System::new("main");

loop {
system.block_on::<_, std::io::Result<()>>(async move {
HttpServer::new(move || App::new().wrap(middleware::Logger::default()))
.bind("127.0.0.1:8080")?
.run()
.await
})?;

// doesn't stop everything...? see https://github.com/actix/actix-web/issues/1249
actix_web::rt::System::current().stop();
}
}
```
`ls -l /proc/[PID]/fd` contains 7 sockets and 28 pipes in the first iteration. Pressing `Ctrl+C` shuts down the server (and the system) and proceeds to the next iteration. This time `ls -l /proc/[PID]/fd` contains 11 sockets and 30 pipes.

Moving `let mut system = ...` into the loop avoids increasing the number of open sockets, but at the same time increases the number of open pipes by 22 in each iteration.

## Context
I am trying to restart the server to change routes/handlers. Since the router is read-only, restarting the server is the only solution that does not involve writing a custom router.

Besides the issue reported here, a simple solution based on https://github.com/actix/examples/tree/master/shutdown-server (slightly extended to differentiate stop/restart) works well.

## Your Environment
* Linux
* Rust Version: 1.46.0
* Actix Web Version: 3.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.