Skip to content

PortInUseFailureAnalyzer should attempt to detect the bounding PID in case of a port conflict #45245

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

Conversation

yonatang
Copy link

@yonatang yonatang commented Apr 21, 2025

Description

Right now, if the port that Spring attempts to bind if already in use, Spring Boot will provide you a general notification saying the port is bound, without any other details:

Description:

Web server failed to start. Port 8080 was already in use.

Action:

Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.

It could be very convenient if the analyzer will make a best-effort attempt to detect the bounding PID and provide it as part of the failure details. Something like this:

Description:

Web server failed to start. Port 8080 was already in use by java (PID: 76781).

Action:

Stop the process java (PID: 76781) that's listening on port 8080 or configure this application to listen on another port.

That would be particularly useful when dealing with development environment with multiple services running at the same time, or a headless process that is still running after an IDE crash.

Implementation details

Java has no way to directly access the details of other processes, but since this is a best-effort attempt, we can try to invoke an OS-specific command to fetch the information. If the attempt to get it failed or timed out, we can fall back to the old generic message; either way to app failed to start, so no harm done.

Assistance required

I don't have a windows environment, I would need help to check it works well in that OS. Running the PortInUseFailureAnalyzerTests unit test on a Windows machine should be suffice, it will invoke the necessary OS specific command.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 21, 2025
@yonatang yonatang changed the title PortInUseFailure provides PID info for port conflicts PortInUseFailureAnalyzer should attempt to detect the bounding PID in case of a port conflict Apr 21, 2025
@philwebb
Copy link
Member

Thanks for the PR, but I personally think the complexity to benefit ratio is little high for this one. Flagging to see what the rest of the team think.

@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Apr 21, 2025
@yonatang
Copy link
Author

@philwebb fair enough, I admit I’m a bit spoiled and tend to lean toward the more comfortable side of things 😅

Notice that some frameworks, such as the react-dev-utils, will let you know that piece of information:
image

The PortInUseFailureAnalyzer will perform a best effort attempt to detect the
PID and process information of the port that bound to the port, and report it
in the failure message.

Signed-off-by: ygraber <[email protected]>
@yonatang yonatang force-pushed the pid_in_PortInUseFailureAnalyzer branch from 9025f66 to 2d30e3c Compare April 22, 2025 04:01
@wilkinsona
Copy link
Member

I'm not sure that it's worth investing much more in this failure analysis while it only works in an English locale.

@philwebb
Copy link
Member

Thanks @wilkinsona, given that additional problem I'm pretty convinced that this isn't something we should add. Thanks anyway for the PR @yonatang!

@philwebb philwebb closed this Apr 22, 2025
@philwebb philwebb added status: declined A suggestion or change that we don't feel we should currently apply and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants