actix / actix/actix-web

Document how to hook/attach handler to "ready to receive connections"

未关闭
#3,714 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
24.8k
派生
1.9k
平均合并
23 小时 10 分钟
30 天内合并 PR
26

描述

I'm currently planning out a PR to fix some race conditions in [miniserve](https://github.com/svenstaro/miniserve)'s test suite, and one of the problem tests is a functional test which has been assuming that, if it waits on a `println!` of bound sockets that happens after `HttpServer::run`, then the sockets will be ready to receive connections.

Given the bug, it's clear that "The [Server](https://docs.rs/actix-web/latest/actix_web/dev/struct.Server.html) must be awaited or polled in order to start running" is more important here, but I'm having trouble finding anything in the actix-web docs about how to hang a handler off "listening threads are ready to receive connections".

Specifically, I need it so I can implement something in the vein of Xephyr's `-displayfd` to more generally solve race conditions in `miniserve`'s test suite:

```
ssokolow@monolith-tng miniserve [test-race-fix] % Xephyr -help
[...]
-displayfd fd file descriptor to write display number to when ready to connect
[...]
```

**NOTE:** I don't even have commit access to miniserve, so "re-architect the entire test suite to use existing testing affordances" probably isn't an answer that I have the authority to bring back and, if given it, I'll probably just incorporate some kind of "sleep-and-retry" loop into the test harness in my PR, given that I sympathize with the desire for integration testing that extends all the way to the CLI arguments and stdout/stderr output.

**EDIT:** I'm assuming the "or polled" may be key, given that I've done similar "Spin the GTK/Qt event loop once to dispatch the queued X11 calls and then exit" stuff in some of my projects with "do one thing, then quit" CLI interfaces, but I don't want to gamble on that.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。