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

"Port is already in use" error on CI when jobs ran in parallel #11003

Open
1 task
tom751 opened this issue May 10, 2024 · 4 comments
Open
1 task

"Port is already in use" error on CI when jobs ran in parallel #11003

tom751 opened this issue May 10, 2024 · 4 comments
Labels
- P2: has workaround Bug, but has workaround (priority)

Comments

@tom751
Copy link

tom751 commented May 10, 2024

Astro Info

Astro                    v4.6.3
Node                     v18.20.2
System                   Linux (x64)
Package Manager          yarn
Output                   static
Adapter                  none
Integrations             @astrojs/react

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I have a CI pipeline on GitLab where jobs can be ran in parallel (e.g a CI runner can be running jobs for multiple merge requests). This causes Vite to throw the following error if multiple astro commands are run at the same time, e.g. astro check or astro sync.

[ERROR] [vite] WebSocket server error: Port is already in use

This causes the pipelines to become flaky as Astro is creating Vite dev servers which are all competing for the same default port 24678. Changing the port in the astro config makes no difference.

I did some digging and the culprit seems to be in 2 places where we create a vite server, and set hmr: false:

From this Vite issue vitejs/vite#13994, it sounds like setting hmr to false doesn't disable the WebSocket which is why I'm seeing the "Port is already in use" error.

I was able to get around this with patch-package and instead of using hmr: false in those places above, I set an object with a random port number, but obviously this isn't ideal. I was able to test this locally by running two commands simultaneously npm run astro check & npm run astro check

Is there a better way to deal with this? Apologies if this is more of a Vite issue than an Astro one!

What's the expected result?

I should be able to run multiple jobs in parallel on CI that use astro CLI commands.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-g3vfoh?file=package.json

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label May 10, 2024
@millette
Copy link
Contributor

I'm getting that too recently, on localhost (dev). It happens with node and db integrations, but I wasn't able to track it down to any integration yet. Other projects don't have this problem. It says "vite error" but everything seems to work anyway.

@matthewp matthewp added - P2: has workaround Bug, but has workaround (priority) and removed needs triage Issue needs to be triaged labels May 13, 2024
@matthewp
Copy link
Contributor

Would love a PR for this.

@bluwy
Copy link
Member

bluwy commented May 14, 2024

vitejs/vite#16219 could help with this once it lands.

@ResearchScientist
Copy link

I'm getting a similar build error here on github codespaces [vite] Websocket server error: Port is already in use.
CI/CD unable to deploy to Netlify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority)
Projects
None yet
Development

No branches or pull requests

5 participants