Server never exits on SIGTERM/SIGINT after serving a native file route while the JSON access log is enabled (stderr lock held by access-log thread)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 83/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- rust
- 領域
- backend, observability
調査の方向性
報告では、src/telemetry.rs の write_access_log 付近と、src/http_server.rs の転送ハイウォーターマーク診断付近が指摘されています。まずアクセスログ書き込みループを読み、次に提供された Roc アプリと SIGTERM の手順で再現してください。ホスト診断が JSON アクセスログ記録と同時にデッドロックせず、静的ファイルへのリクエスト後にサーバーが終了すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
With a JSON-lines access log enabled, a server that has served any native file route never exits on SIGTERM or SIGINT. shutdown! never runs, the 30 s drain deadline never forces an exit, and a second Ctrl-C does nothing. Only kill -9 stops it.
Reproduction
basic-webserver 0.22.0, Roc 0.1.0 (Homebrew), macOS 26.2 arm64.
app [Context, program] {
http: "https://github.com/roc-lang/http/releases/download/1.0.0/6ZUwqYhCS8PU9Mo6MF7oV82ET2o7KYb57CLKDq4cq4sS.tar.zst",
pf: platform "https://github.com/roc-lang/basic-webserver/releases/download/0.22.0/BM2BUXA8mwbcoKPUfRV8cLtsUdnsSBPwjNLPRUJQAQ7Q.tar.zst",
roc: "0.1.0",
}
import pf.Path
import pf.Server
import pf.Stdout
import http.Response
Context : {}
program = { init!, respond!, shutdown! }
init! : () => Try({ config : Server.Config, context : Context }, [Exit(I64)])
init! = || {
files = Server.file_root({ id: "public", path: Path.utf8("public") })
config =
Server.default_config
.with_file_roots([files])
.with_native_routes({
files: [Server.static_mount({ at: "/static", files })],
liveness: [],
readiness: [],
})
.with_access_log(Server.json_lines_access_log({ target: Server.path_without_query, max_buffered_events: 256 }))
Ok({ config, context: {} })
}
respond! : Server.Request, Context => Try(Server.Outcome, [ServerErr(Str)])
respond! = |_request, _context| Ok(Server.respond(Response.from_status(200).with_body(Str.to_utf8("roc"))))
shutdown! : Server.ShutdownReason, Context => Try({}, [Exit(I64)])
shutdown! = |reason, _context| {
Stdout.line!("shutdown! ran: ${Str.inspect(reason)}") ?? {}
Ok({})
}
mkdir public && echo hi > public/a.txt
roc build main.roc
./main & P=$!; sleep 1.5
curl -s localhost:8000/static/a.txt
kill -TERM $P # the process is still running 45 s later; shutdown! never prints
Results, 10 runs each unless noted (exit checked within 2 s):
| Access log | Requests before SIGTERM | Result |
|---|---|---|
| on | static file | hangs 10/10; still running after 45 s |
| on | static 404 (/static/missing.txt) |
hangs |
| on | Roc route only, or none | exits in about 1 s |
| off | static file | exits 10/10 |
file_root_with_cache and open_metrics make no difference.
Cause
A sample of the hung process shows the main thread inside http_server::run_tcp_server, in std::io::stdio::_eprint, blocked on the stderr reentrant mutex (__psynch_mutexwait). The basic-webserver-access-log thread is idle in mpmc::Receiver<String>::recv, and every tokio worker is parked.
write_access_log takes the stderr lock once and keeps it for the thread's lifetime, including while it blocks waiting for the next line:
https://github.com/roc-lang/basic-webserver/blob/4536fe5/src/telemetry.rs#L851-L853
let stderr = io::stderr();
let mut writer = BufWriter::new(stderr.lock());
while let Ok(line) = receiver.recv() {
Every eprintln! on another thread therefore blocks until the access-log thread exits, and it does not exit before shutdown finishes. After a native file transfer, run_server_with_listener prints the transfer high-water mark after draining, so shutdown deadlocks there:
https://github.com/roc-lang/basic-webserver/blob/4536fe5/src/http_server.rs#L3051-L3055
Without a file transfer the high-water mark is 0, nothing is printed, and shutdown completes. The same lock explains why the safety valves don't help: the drain-deadline exit (Graceful drain exceeded ...) and the Second termination signal received; forcing process exit path both call eprintln! before process::exit. The request-body sink high-water message and every other host eprintln! (Invalid Roc response, connection errors, and so on) can block the same way while the access log is active.
Possible fix
Lock stderr per line instead of for the thread's lifetime, for example let mut writer = io::stderr().lock(); inside the loop around each writeln! and flush, or BufWriter::new(io::stderr()) so each write locks briefly. Then host diagnostics interleave with access-log lines at line boundaries instead of blocking.
- 主要言語
- HTML
- スター
- 110
- フォーク
- 25
- 平均マージ
- 18時間 28分
- マージ済み PR(30日)
- 16
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
roc-lang/basic-webserver のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
roc-lang/basic-webserver#274 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
roc-lang/basic-webserver#273 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
roc-lang/basic-webserver#272 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
roc-lang/basic-webserver#265 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 28/100
roc-lang/basic-webserver#231 ·
メンテナーはふだん 1 日以内に返信
roc-lang/basic-webserver の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
OHDSI/Data2Evidence#3815 ·
メンテナーはふだん 3 日以内に返信
-
e2e-failure ready-to-code
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
redhat-developer/rhdh-plugin-export-overlays#4995 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
fidelity
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: Azure SAS signing uses local time instead of UTC, shifting validity window on non-UTC hosts対応中かも @huanghaoyuanhhy が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
zilliztech/milvus-backup#1418 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] download repeatedly fetches unchanged gzip responses due to compressed/decoded size mismatch対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
stanfordnlp/dspy#11000 ·
メンテナーはふだん 1 日以内に返信