Skip to content
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

[editor] Functionality to run server on multiple configs without specifying port #624

Merged
merged 1 commit into from
Dec 26, 2023

Conversation

Ankush-lastmile
Copy link
Member

@Ankush-lastmile Ankush-lastmile commented Dec 26, 2023

[editor] Functionality to run server on multiple configs without specifying port

What:

Before creating the server process, check if the port to be used is taken. If so, find the next available one before continuing

for context: this builds on top of #619

Why

When running the editor, user should be able to open multiple configs.

Under the hood this means spinning up another server in an unused port. Frontend already supports dynamic ports.

Testplan

  1. yarn build in aiconfig/python/src/aiconfig/editor/client
  2. Open two aiconfigs with "prod" editor"
Getting Started aiconfig Chain Of Verification aiconfig
Screenshot 1 Screenshot 2
Screenshot 3 Screenshot 4

Terminals showcase the command used to open editor. Each one has a seperate config file path. No port is passed in from the user.

Chain of verification Uses Port 8080
Getting Started in a new process using Port 8081

…ifying port

## What:

Before creating the server process, check if the port to be used is taken. If so, find the next available one before continuing


## Why

When running the editor, user should be able to open multiple configs.

Under the hood this means spinning up another server in an unused port. Frontend already supports dynamic ports.

## Testplan

1. yarn build in aiconfig/python/src/aiconfig/editor/client
2. Open two aiconfigs with "prod" editor"

| Getting Started | Chain Of Verification |
|------------|-------------|
| ![Screenshot 1](https://github.com/lastmile-ai/aiconfig/assets/141073967/d30c9366-49d7-4b6d-851c-e469d47c4063) |  ![Screenshot 2](https://github.com/lastmile-ai/aiconfig/assets/141073967/74c53dcc-52b6-4b67-84e1-7c8900045d4a)|
| ![Screenshot 3](https://github.com/lastmile-ai/aiconfig/assets/141073967/6e86aa4f-8d7d-4140-b3ad-b374a90ae276) | ![Screenshot 4](https://github.com/lastmile-ai/aiconfig/assets/141073967/204120fa-305d-44b0-be3c-de33c342aa3c)|
@Ankush-lastmile Ankush-lastmile changed the title [editor] WIP Functiionality to run server on multiple configs [editor] Functionality to run server on multiple configs without specifying port Dec 26, 2023
@Ankush-lastmile Ankush-lastmile marked this pull request as ready for review December 26, 2023 21:52
@rholinshead
Copy link
Contributor

In the second screenshot, the terminal output shows port 8082 but browser shows 8081. Just double-checking this is just an incorrect image / I assume you ran it once more after 8081 was already in use?

Copy link
Contributor

@rholinshead rholinshead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@saqadri saqadri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thanks a lot for the simple fix

@Ankush-lastmile
Copy link
Member Author

Ankush-lastmile commented Dec 26, 2023

In the second screenshot, the terminal output shows port 8082 but browser shows 8081. Just double-checking this is just an incorrect image / I assume you ran it once more after 8081 was already in use?

Yes it was an incorrect usage/testplan, good catch. Re-executed test plan and the ports are as expected. Updated Testplan as well

@Ankush-lastmile Ankush-lastmile merged commit d3f1262 into main Dec 26, 2023
2 checks passed
Comment on lines +88 to +90
edit_config_dict = edit_config.model_dump()
edit_config_dict["server_port"] = port
edit_config = EditServerConfig(**edit_config_dict)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit_config_dict["server_port"] = port
edit_config = EditServerConfig(**edit_config_dict)

LOGGER.warning(f"Using {port}.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: .info

@@ -64,8 +65,33 @@ def _sigint(procs: list[subprocess.Popen[bytes]]) -> Result[str, str]:
p.send_signal(signal.SIGINT)
return Ok("Sent SIGINT to frontend servers.")

def is_port_in_use(port: int) -> bool:
Copy link
Contributor

@jonathanlastmileai jonathanlastmileai Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now, but there are both functional and UX problems with this approach.

Functional: It might be unlikely, but technically you can have a race condition where the port gets used after this returns but before the flask server starts.

UX: If I pass a port explicitly and it's already in use, I expect an error. I don't want the app to find the next open port for me.

Here's what I would have done:

  • If user provides port, don't do any special logic
  • Otherwise, loop over all possible ports (e.g. starting at 8080) and try to start the server until one works, catching an exception for in use.

cc @saqadri , @rossdanlm

Copy link
Contributor

@rossdanlm rossdanlm Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, but I think this could be seen as an enhancement instead of a bug. I made a GH issue for this in #633 as a bootcamp task that others can do if they like

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.

5 participants