Skip to content

fix: made studio start on different port if one is already in use #1815

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
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

neoandmatrix
Copy link
Contributor

Description

The PR adds the functionality to automatically start a new instance of studio on a different port if the current port intended to be used is already in use.

image

An info is displayed that the specified port was already in use hence a different port is being used to the user.

Related issue(s)
Resolves #1797

Signed-off-by: Tushar Anand <tusharannand@gmail.com>
Copy link

changeset-bot bot commented Jul 6, 2025

🦋 Changeset detected

Latest commit: 1416652

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Jul 6, 2025

Changeset has been generated for this PR as part of auto-changeset workflow.

Please review the changeset before merging the PR.
---
'@asyncapi/cli': patch
---

fix: made studio start on different port if one is already in use

- 43a8cb8: fix: made studio start on differnt port if one is already in use

Signed-off-by: Tushar Anand <tusharannand@gmail.com>

If you are a maintainer or the author of the PR, you can change the changeset by clicking here

Tip

If you don't want auto-changeset to run on this PR, you can add the label skip-changeset to the PR or remove the changeset and change PR title to something other than fix: or feat:.

@aeworxet
Copy link
Contributor

@asyncapi/bounty_team

@aeworxet aeworxet moved this to In Progress in Bounty Program Jul 22, 2025
@neoandmatrix
Copy link
Contributor Author

Hey @AayushSaini101 @Shurtu-gal if possible can this be reviewed and merged as #1824 is dependent on this.

Thanks

@neoandmatrix
Copy link
Contributor Author

Hey @AayushSaini101 @Shurtu-gal any update on this ?

@Shurtu-gal
Copy link
Collaborator

I guess we should not go ahead with this iterative checking of ports. Can use stuff like: https://expressjs.com/en/api.html#app.listen

Basically mentioning port as 0 gets the OS to allocate a port.

@neoandmatrix
Copy link
Contributor Author

neoandmatrix commented Jul 28, 2025

I guess we should not go ahead with this iterative checking of ports. Can use stuff like: https://expressjs.com/en/api.html#app.listen

Is this specific to express.js? I believe we are not using express.

And also it might cause inconsistency as OS will always assign a random port with this method not only for case if port is already in use.

@Shurtu-gal
Copy link
Collaborator

We are using nodejs http which has the same functionality.

@neoandmatrix
Copy link
Contributor Author

Okay but assigning a random port every time , would it be a good practice and experience ? Also it will make testing harder i believe.

@neoandmatrix
Copy link
Contributor Author

One concern for me with the random port approach is testing these commands through puppeteer. As we need to navigate to the url for testing and since we include port in the url query parameters it being random would make it extremely difficult to navigate that site and test the instance as url would be random every time.

Inferring it from logs is extremely difficult as it would require a lot of parsing which make tests un-reliable.

Passing the port through flag is also not possible as we can only pass strings in parameter in tests but port require a number which cannot be passed.

@neoandmatrix
Copy link
Contributor Author

Hey @Shurtu-gal with respect to above discussion how should i proceed with this ?

@Shurtu-gal
Copy link
Collaborator

I suppose we can wait for @AayushSaini101 or @Souvikns input also.

@AayushSaini101
Copy link
Collaborator

/u

Copy link

@AayushSaini101
Copy link
Collaborator

https://expressjs.com/en/api.html#app.listen

I guess we should not go ahead with this iterative checking of ports. Can use stuff like: https://expressjs.com/en/api.html#app.listen

Basically mentioning port as 0 gets the OS to allocate a port.

I guess we can go for iterating port allocation to the server, explicitly allocating the port is not a proper way, wdyt @Souvikns

@Shurtu-gal
Copy link
Collaborator

I guess we can go for iterating port allocation to the server

Setting up server and checking each port is not the way to go according to me.

explicitly allocating the port is not a proper way

I couldn't understand this.

@aeworxet
Copy link
Contributor

npm install portfinder installs four packages and takes 1.3 MB.
Are these quantities and size a significant concern in this case?

$ ls
async
debug
ms
portfinder

$ du -h
32K	./debug/src
68K	./debug
444K	./async/dist
112K	./async/internal
1.1M	./async
20K	./ms
24K	./portfinder/lib
40K	./portfinder
1.3M	.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty AsyncAPI Bounty program related label
Projects
Status: In Progress
Status: To Triage
Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Allow starting of other instance of studio if one is already running.
5 participants