-
Notifications
You must be signed in to change notification settings - Fork 453
feat: [ENG-2857] surface port-in-use error in brv webui #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ncnthien
wants to merge
10
commits into
main
Choose a base branch
from
feat/ENG-2857
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
83bd7f5
feat: [ENG-2857] surface port-in-use error in brv webui
ncnthien 7045f28
feat: [ENG-2857] address PR feedback — explicit status discriminator,…
ncnthien 3b3896d
feat: [ENG-2857] gate httpServer cleanup to startup phase to avoid we…
ncnthien 96337b3
Merge branch 'main' into feat/ENG-2857
ncnthien 8838e8e
Merge branch 'main' into feat/ENG-2857
ncnthien 6d3fa5d
feat: [ENG-2857] auto-fallback Web UI to next port when default is in…
ncnthien adbb0d3
feat: [ENG-2857] extract testable fallback helper + honor explicit po…
ncnthien 469796e
feat: [ENG-2857] explicit status on StartWebUiOutcome, split ok varia…
ncnthien 77ba89f
feat: [ENG-2857] revert CLI URL to localhost per product preference
ncnthien 1bd56b5
feat: [ENG-2857] untrack MANUAL_TEST_ENG-2857.md (local QA artifact)
ncnthien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| export class WebUiError extends Error { | ||
| public constructor(message: string) { | ||
| super(message) | ||
| this.name = 'WebUiError' | ||
| } | ||
| } | ||
|
|
||
| export class WebUiPortInUseError extends WebUiError { | ||
| public readonly port: number | ||
|
|
||
| public constructor(port: number) { | ||
| super(`Web UI port ${port} is already in use`) | ||
| this.name = 'WebUiPortInUseError' | ||
| this.port = port | ||
| } | ||
| } | ||
|
|
||
| export class WebUiServerAlreadyRunningError extends WebUiError { | ||
| public constructor() { | ||
| super('Web UI server is already running') | ||
| this.name = 'WebUiServerAlreadyRunningError' | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import {WebUiPortInUseError} from '../../core/domain/errors/webui-error.js' | ||
|
|
||
| export interface WebUiStarter { | ||
| start(port: number): Promise<void> | ||
| } | ||
|
|
||
| export type StartWebUiOutcome = | ||
| | {actualPort: number; requestedPort: number; status: 'ok'} | ||
| | {error: unknown; status: 'error'} | ||
|
ncnthien marked this conversation as resolved.
|
||
|
|
||
| export async function startWebUiWithFallback( | ||
| server: WebUiStarter, | ||
| preferredPort: number, | ||
| maxAttempts: number, | ||
| ): Promise<StartWebUiOutcome> { | ||
| let lastError: unknown | ||
| for (let offset = 0; offset < maxAttempts; offset++) { | ||
| const attemptPort = preferredPort + offset | ||
| try { | ||
| // eslint-disable-next-line no-await-in-loop -- intentional sequential fallback | ||
| await server.start(attemptPort) | ||
| return {actualPort: attemptPort, requestedPort: preferredPort, status: 'ok'} | ||
| } catch (error) { | ||
| lastError = error | ||
| if (error instanceof WebUiPortInUseError) continue | ||
| break | ||
| } | ||
| } | ||
|
|
||
| return {error: lastError, status: 'error'} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| export const WebuiEvents = { | ||
| GET_PORT: 'webui:getPort', | ||
| SET_PORT: 'webui:setPort', | ||
| } as const | ||
|
|
||
| type WebuiGetPortOkResponse = {port: number; requestedPort?: number; status: 'ok'} | ||
| type WebuiPortInUseResponse = {conflictPort: number; status: 'port_in_use'} | ||
| type WebuiSetPortOkResponse = {port: number; status: 'ok'} | ||
|
|
||
| export type WebuiGetPortResponse = WebuiGetPortOkResponse | WebuiPortInUseResponse | {status: 'not_started'} | ||
|
|
||
| export interface WebuiSetPortRequest { | ||
| port: number | ||
| } | ||
|
|
||
| export type WebuiSetPortResponse = WebuiPortInUseResponse | WebuiSetPortOkResponse | ||
|
ncnthien marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.