qioo777 opened a new pull request, #227:
URL: https://github.com/apache/casbin-gateway/pull/227
## Problem
On Windows, updating from the version button installs the new build and the
UI
reaches "Restarting into the new version", but the Gateway often does not
come
back. The window keeps showing the old page until the app is closed and
opened
by hand, after which the new version runs normally.
## Reproduction
Update a desktop installation whose server is still holding the management
port
when the new one starts. The new Gateway writes:
Casbin Gateway: cannot listen on port 17000: port 17000 is held by
pid 16504, casbin-gateway.exe.old, which is not Casbin Gateway
and exits with ExitCodeFatalConfig. In one installation's log this happened
on
eight separate updates; the one that worked shows the holder named
`casbin-gateway.exe`, before the rename.
## Root cause
`swap()` renames the running executable to `casbin-gateway.exe.old` before
starting the new one, and Windows reports a running process under the name
its
file has now. `executableBaseName` stripped only a trailing `.exe`, so that
name
normalised to `casbin-gateway.exe.old` rather than `casbin-gateway`, and
`isSelfExecutable` did not match it.
So the Gateway restarting into the update mistook the very process it was
replacing for an unrelated program: `StopOldInstance` returned a
`ForeignPortError`, `ClaimPort` returned at once instead of waiting for the
port,
and `main` called `FatalListenError`. The new version exited, the one it
replaced
exited a moment later and nothing was left serving. `RestartDesktopLauncher`
is
only reached once `ClaimPort` succeeds, so the tray was never told to
restart and
the page went on polling a Gateway that was not there.
## Fix
Strip the suffixes an update leaves behind (`.old`, and `.failed` from a
rollback) before the name comparison.
## Tests
- New `TestExecutableBaseName` and `TestIsSelfExecutableAcrossAnUpdate` in
`util/port_test.go`; both fail without the change.
- A process run out of `casbin-gateway.exe.old` holding a port is now taken
over
("stopped the previous Gateway (pid …, casbin-gateway.exe.old)") where
before
the claim failed with exit 78.
- `go test -tags skipCi ./...`, `go build ./...`, the desktop module, and the
Windows release build with `-tags embed`; `yarn lint` and `yarn build`.
--
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]