mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8233430: (sc) Socket adaptor restoring of blocking mode can override exception if socket closed
Reviewed-by: dfuchs, chegar
This commit is contained in:
parent
db4909bf99
commit
fd077ea9ae
3 changed files with 47 additions and 13 deletions
|
@ -332,8 +332,8 @@ class ServerSocketChannelImpl
|
|||
n = Net.accept(fd, newfd, isaa);
|
||||
}
|
||||
} finally {
|
||||
// restore socket to blocking mode
|
||||
lockedConfigureBlocking(true);
|
||||
// restore socket to blocking mode (if channel is open)
|
||||
tryLockedConfigureBlocking(true);
|
||||
}
|
||||
} finally {
|
||||
end(true, n > 0);
|
||||
|
@ -376,7 +376,7 @@ class ServerSocketChannelImpl
|
|||
}
|
||||
|
||||
/**
|
||||
* Adjust the blocking mode while holding acceptLock.
|
||||
* Adjust the blocking. acceptLock must already be held.
|
||||
*/
|
||||
private void lockedConfigureBlocking(boolean block) throws IOException {
|
||||
assert acceptLock.isHeldByCurrentThread();
|
||||
|
@ -386,6 +386,25 @@ class ServerSocketChannelImpl
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the blocking mode if the channel is open. acceptLock must already
|
||||
* be held.
|
||||
*
|
||||
* @return {@code true} if the blocking mode was adjusted, {@code false} if
|
||||
* the blocking mode was not adjusted because the channel is closed
|
||||
*/
|
||||
private boolean tryLockedConfigureBlocking(boolean block) throws IOException {
|
||||
assert acceptLock.isHeldByCurrentThread();
|
||||
synchronized (stateLock) {
|
||||
if (isOpen()) {
|
||||
IOUtil.configureBlocking(fd, block);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the socket if there are no accept in progress and the channel is
|
||||
* not registered with a Selector.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue