PortInUseFailureAnalyzer should attempt to detect the bounding PID in case of a port conflict #45245
+222
−5
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.
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:
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:
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.