8334719: (se) Deferred close of SelectableChannel may result in a Selector doing the final close before concurrent I/O on channel has completed

Co-authored-by: Alan Bateman <alanb@openjdk.org>
Reviewed-by: alanb, dfuchs
This commit is contained in:
Jaikiran Pai 2024-06-27 04:38:32 +00:00
parent 6682305ee2
commit 9bb675f89d
7 changed files with 705 additions and 0 deletions

View file

@ -1945,6 +1945,11 @@ class DatagramChannelImpl
@Override
public void kill() {
// wait for any read/write operations to complete before trying to close
readLock.lock();
readLock.unlock();
writeLock.lock();
writeLock.unlock();
synchronized (stateLock) {
if (state == ST_CLOSING) {
tryFinishClose();

View file

@ -654,6 +654,9 @@ class ServerSocketChannelImpl
@Override
public void kill() {
// wait for any accept operation to complete before trying to close
acceptLock.lock();
acceptLock.unlock();
synchronized (stateLock) {
if (state == ST_CLOSING) {
tryFinishClose();

View file

@ -1216,6 +1216,11 @@ class SocketChannelImpl
@Override
public void kill() {
// wait for any read/write operations to complete before trying to close
readLock.lock();
readLock.unlock();
writeLock.lock();
writeLock.unlock();
synchronized (stateLock) {
if (state == ST_CLOSING) {
tryFinishClose();