bitflicker64 opened a new pull request, #3044:
URL: https://github.com/apache/hugegraph/pull/3044
## Fix foreground mode in `start-hugegraph.sh` (chunk 1 of #3043)
### Problem
In foreground mode (`-d false`), `start-hugegraph.sh` had a structural
bug: all post-branch logic ran **unconditionally after** the
daemon/foreground
`if/else` block.
In foreground mode the script blocks at `hugegraph-server.sh` until Java
exits. After Java exits:
- `PID="$!"` captures an empty string (no background job)
- `bin/pid` is written with an empty string
- `wait_for_startup` fails immediately (empty PID, Java already dead)
- `disown` fails (no background jobs)
- `OPEN_MONITOR` fires unconditionally — even in foreground mode
- The script exits 0, losing Java's exit code entirely
This means a Java crash in foreground mode is invisible to the process
supervisor (Docker restart policy, systemd, etc.).
### Fix
- Move all post-branch logic (`PID="$!"`, pid file write, `trap`,
`wait_for_startup`, `disown`, `OPEN_MONITOR`) inside the
`DAEMON == "true"` branch where it belongs.
- In the foreground branch: background Java with `&`, capture `$!`,
write the pid file, then `wait $PID` (so the script blocks while Java
runs) and `exit $?` (so Java's exit code propagates out).
- Gate `OPEN_MONITOR` inside the daemon branch — monitor setup after a
blocking foreground call makes no sense.
### Also included
- Fix `restserver.url` in `rest-server.properties` to include the
`http://` scheme prefix (was `127.0.0.1:8080`, now
`http://127.0.0.1:8080`). The `check_port` and URL parsing in
`util.sh` expect a full URL.
### Tests
New script:
`hugegraph-server/hugegraph-dist/src/assembly/travis/test-start-hugegraph.sh`
| Test | Unmodified code | After fix |
|---|---|---|
| Test 1 — daemon mode regression | PASS | PASS |
| Test 2 — foreground mode blocks | PASS | PASS |
| Test 3 — exit code propagates (137 on SIGKILL) | **FAIL** | PASS |
| Test 4 — `-m true` registers cron in daemon mode | PASS | PASS |
Wired into `server-ci.yml` after the Compile step, rocksdb backend only
(foreground mode behavior is backend-independent).
### What this does NOT include
Docker entrypoint changes and runtime restart validation (kill Java
inside container → container exits → Docker restarts it) are in the
follow-up PR for chunks 4–8.
Relates to #3043 (chunk 1 of 3 startup script fixes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]