Skip to content

fix(scripts): auto-switch dev.port when it's already in use#2867

Open
hongwei1 wants to merge 1 commit into
OpenBankProject:developfrom
hongwei1:fix/obp-api-test-scripts-port-auto-switch
Open

fix(scripts): auto-switch dev.port when it's already in use#2867
hongwei1 wants to merge 1 commit into
OpenBankProject:developfrom
hongwei1:fix/obp-api-test-scripts-port-auto-switch

Conversation

@hongwei1

Copy link
Copy Markdown
Contributor

Summary

  • flushall_build_and_run.sh and flushall_fast_build_and_run.sh now probe dev.port (default 8080) before starting the server; if it's already bound, they walk forward to the next free port in a 50-port range and export it via OBP_DEV_PORT (no props-file change needed, since APIUtil.getPropsValue checks env vars before props). Both scripts print PORT: <n> alongside the existing PID: <n> line.
  • Fixes a hang in flushall_build_and_run.sh's background mode: it launched the server with > >(tee "$RUNTIME_LOG") 2>&1, a process substitution whose inner tee inherits the script's own stdout fd. When a caller captures this script's output via $(... | tee ...) (the pattern the local obp-api-test smoke-test skill uses), that inherited fd keeps the caller's pipe open for as long as the server runs, so the command substitution never returns even though the meaningful output already printed. Switched to a plain file redirect, matching flushall_fast_build_and_run.sh (which never had this problem).

Test plan

  • Verified both scripts auto-switch to a free port when 8080 is occupied by another local process, and the server boots and answers /root on the new port
  • Verified the previously-hanging out=$(./flushall_build_and_run.sh --background 2>&1 | tee /dev/stderr) pattern now returns promptly after printing PID/PORT
  • Ran the full local obp-api-test 6-step smoke test end-to-end (test suite → build+run → get root → kill → fast-rebuild+run → get root) with port 8080 occupied — all 6 steps passed

flushall_build_and_run.sh and flushall_fast_build_and_run.sh always started
the HTTP4S server on the configured dev.port (default 8080). If that port was
already bound by another local process (e.g. another OBP-API instance), the
new server failed to bind or the caller had no way to know a fallback was
needed. Both scripts now probe the port before starting the server and, if
busy, walk forward to the next free port in a 50-port range, exporting it via
OBP_DEV_PORT (APIUtil.getPropsValue checks env vars before props, so this
requires no props-file change) and printing "PORT: <n>" alongside the
existing "PID: <n>" line.

Also fixes a hang in flushall_build_and_run.sh's background mode: it launched
java with `> >(tee "$RUNTIME_LOG") 2>&1`, a process substitution whose inner
tee inherits the script's own stdout fd. When this script is invoked from a
caller that captures its output via command substitution piped through tee
(e.g. `out=$(./flushall_build_and_run.sh --background 2>&1 | tee /dev/stderr)`,
the pattern smoke_test.sh uses), that inherited fd keeps the caller's pipe
open for as long as the server runs, so the command substitution never
returns even though the meaningful output already printed. Switched to a
plain file redirect (matching flushall_fast_build_and_run.sh, which never had
this problem), so the script's own file descriptors close cleanly on exit
regardless of the backgrounded server's lifetime.
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant