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

Deprecate SocketUtils #28052

Closed
sbrannen opened this issue Feb 15, 2022 · 5 comments
Closed

Deprecate SocketUtils #28052

sbrannen opened this issue Feb 15, 2022 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Feb 15, 2022

SocketUtils was introduced in Spring Framework 4.0, primarily to assist in writing integration tests which start an external server on an available random port.

However, these utilities make no guarantee about the subsequent availability of a given port and are therefore unreliable.

Instead of using SocketUtils to find an available local port for a server, it is recommended that users rely on a server's ability to start on a random port that it selects or is assigned by the operating system. To interact with that server, the user should query the server for the port it is currently using.

@sbrannen sbrannen added the type: task A general task label Feb 15, 2022
@sbrannen sbrannen added this to the 5.3.16 milestone Feb 15, 2022
@sbrannen sbrannen self-assigned this Feb 15, 2022
@snicoll snicoll added type: enhancement A general enhancement and removed type: task A general task labels Feb 15, 2022
@snicoll
Copy link
Member

snicoll commented Feb 15, 2022

This is a user-facing change that should be visible in the changelog so I've switched the issue type to enhancement.

sbrannen added a commit to sbrannen/spring-framework that referenced this issue Feb 15, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Feb 15, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Feb 15, 2022
@sbrannen sbrannen changed the title Deprecate SocketUtils in 5.3.x and remove in 6.0 Deprecate SocketUtils Feb 15, 2022
@sbrannen
Copy link
Member Author

FYI: SocketUtils has been removed in Spring Framework 6.0 M3.

@chrylis
Copy link

chrylis commented Mar 18, 2022

I know that a PR to remove SocketUtils has already been merged, but I will make a note requesting a revert of the removal. Despite the comment in the Javadoc to "rely on a server's ability to start on a random port", the assumption that the external dependency has such an ability is not well-founded; the DynamoDB Local server, in particular, does not have this feature, and I'm using findAvailableTcpPort for this purpose. The only suitable replacement will be to clone the code anyway.

As an alternative, would moving this to Spring Test be sensible?

@sbrannen
Copy link
Member Author

Hi @chrylis,

Thanks for the feedback.

As an alternative, would moving this to Spring Test be sensible?

We are considering introducing an alternative (with reduced scope) for testing scenarios only in spring-test. If so, it could potentially look similar to TestSocketUtils, though the final API might be different.

We will continue to deliberate this and listen to community feedback.

@sbrannen
Copy link
Member Author

Please note that the team plans to introduce TestSocketUtils in Spring Framework 5.3.18. See #28210 for details.

sbrannen pushed a commit to sbrannen/spring-framework that referenced this issue Nov 14, 2022
SocketUtils was officially deprecated in 5.3.16 (spring-projectsgh-28052) and removed
in 6.0 M3 (spring-projectsgh-28054); however, there is still need for a subset of this
functionality in integration tests for testing scenarios in which it is
not possible for the system under test to select its own random port
(or rely on the operating system to provide an ephemeral port).

This commit therefore introduces a scaled down version in the
spring-test module called TestSocketUtils which supports retrieval of a
single TCP port.

See spring-projectsgh-29132
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants