Integrated: 8278270: ServerSocket is not thread safe
Alan Bateman
alanb at openjdk.java.net
Tue Dec 7 08:52:22 UTC 2021
On Sun, 5 Dec 2021 16:44:05 GMT, Alan Bateman <alanb at openjdk.org> wrote:
> There are several thread safety issues in java.net.ServerSocket, issues that go back to at least JDK 1.4.
>
> The issue of most concern is async close of a ServerSocket that is initially created unbound and where close may be called at or around the time the underlying SocketImpl is created or the socket is bound.
>
> The summary of the changes are:
>
> 1. The "impl" field is changed to be final field.
> 2. The closeLock is renamed to stateLock and is required to change the (now volatile) created, bound or closed fields.
> 3. The needless synchronization has been removed from xxxSoTimeout and xxxReceiveBufferSize.
>
> There are many redundant checks for isClosed() and other state that could be removed. Removing them would subtle change the exception thrown when there are two or more failure conditions. So they are left as is.
This pull request has now been integrated.
Changeset: 24877ac0
Author: Alan Bateman <alanb at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/24877ac0788d3db9f2e9c7492a0d3e42244e7e06
Stats: 100 lines in 1 file changed: 35 ins; 34 del; 31 mod
8278270: ServerSocket is not thread safe
Reviewed-by: dfuchs
-------------
PR: https://git.openjdk.java.net/jdk/pull/6712
More information about the net-dev
mailing list