Server process keeps running after a startup failure
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 38/100
调研方向
Start with Mirth.run(), Mirth.startup(), and the referenced lines in Mirth.java, then inspect how MirthLauncher waits for the run thread and how EventController owns the consumer threads. Reproduce the occupied-port case with ./oieserver and the migration failure using the provided Derby steps; also compare the shutdown-hook behavior affected by #499. Done means either startup failure terminates the process with a non-zero status, no consumer thread keeps the JVM alive, and failed-migration shutdown does not hang.
由索引模型根据 Issue 内容生成。
描述
Summary
When the server fails to start, it logs the error and stops starting up, but the JVM does not exit. The process stays up with no listening ports, so a service manager sees it as running and nothing restarts or alerts.
This happens with ordinary failures, not just unusual ones. Two confirmed triggers:
- A port already in use, for example from a second instance or another service on 8443.
- A failed database migration (
MigrationException).
Steps to reproduce
Run these from the server's install directory.
A port already in use
- Occupy the HTTPS port, for example in another terminal:
(Traditional netcat needsnc -l 8443nc -l -p 8443.) - Start the server:
./oieserver
A failed migration
With the default Derby database:
- Start a fresh install once so the database is created, then stop it (Ctrl+C once startup has finished):
./oieserver - With the server stopped, set a schema version this release doesn't know:
java -cp 'server-lib/database/*' org.apache.derby.tools.ij <<'EOF' connect 'jdbc:derby:appdata/mirthdb'; UPDATE SCHEMA_INFO SET VERSION = '99.0.0'; exit; EOF - Start the server again:
./oieserver
The migration fails with or without the fix for #496 (unrecognized schema version). Only the logged error differs.
Expected
The process exits with a non-zero status after logging the failure.
Actual
Port in use: the log shows https.port port is already in use: 8443, then nothing. The Java process keeps running with no listening ports. SIGTERM stops it within a couple of seconds, because the shutdown hook was never registered.
Failed migration: reproduced with Derby and with PostgreSQL 16. The log shows Failed to migrate database schema (and on Derby, Database shut down normally.), then nothing. The Java process keeps running with no listening ports.
In both cases a thread dump shows the same two non-daemon threads keeping the JVM alive:
AuditableEventListener Consumer ThreadDefaultAlertWorker Consumer Thread
Cause
Production starts the server through MirthLauncher, which runs Mirth as a thread, so the process only exits once every non-daemon thread has ended. Each EventListener starts its consumer thread in its constructor, when Mirth creates its EventController, and nothing stops those threads on a failed startup.
Both failures end Mirth.run() without stopping them:
- Port in use: the port check returns from
Mirth.run()beforestartup()is called and before the shutdown hook is registered (Mirth.java:148-154). - Failed migration:
Mirth.startup()setsrunning = falseand returns (Mirth.java:320-326), soMirth.run()ends.
The System.exit(0) in Mirth.main() never runs on these paths, because main() is only used by devRun. When the server is started that way, main() calls System.exit(0) once run() returns, so the status is 0. After a failed migration, that exit also runs the shutdown hook, which on Derby should hang as described in #499. This path was not tested.
Suggested fix
On a startup failure, end the process with a non-zero status. One option is for Mirth.run() to record the failure and for the launcher, or Mirth itself, to call System.exit(1). The early System.exit(0) on a failed database connection (Mirth.java:303) should use a non-zero status too. The shutdown hook is already registered by then (Mirth.java:162), so that exit also runs it.
For failures inside startup(), such as a failed migration, this has to be fixed together with #499. System.exit runs the JVM shutdown hook, and after a migration failure on Derby that hook hangs, so on its own a System.exit(1) would leave the process stuck in the hook instead of idle. The port check runs before the hook is registered, so that case doesn't depend on the shutdown-hook fix.
🤖 Drafted with Claude Code
- 主要语言
- Java
- 星标
- 227
- 派生
- 81
- 平均合并
- 2 天 16 小时
- 30 天内合并 PR
- 12
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
OpenIntegrationEngine/engine 的其他 Issue
-
Outdated GitHub workflow action versions可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
OpenIntegrationEngine/engine#485 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 62/100
OpenIntegrationEngine/engine#478 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
OpenIntegrationEngine/engine#355 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
OpenIntegrationEngine/engine#347 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
OpenIntegrationEngine/engine#313 ·
维护者通常 1 天内回复
查看 OpenIntegrationEngine/engine 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
-
account bug communication lecture
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
area/server bug P2
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/java-sdk#1196 ·
维护者通常 1 天内回复