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 摘要。