Fix Exceptions in EventHandler#postHandling Breaking Select Loop (#44347) (#44396)

* Fix Exceptions in EventHandler#postHandling Breaking Select Loop

* We can run into the `write` path for SSL channels when they are not fully registered (if registration fails and a close message is attempted to be written) and thus into NPEs from missing selection keys
  * This is a quick fix to quiet down tests, a cleaner solution will be incoming for #44343
* Relates #44343
This commit is contained in:
Armin Braun 2019-07-16 07:06:26 +02:00 committed by GitHub
parent 099d52f3b0
commit 5c8275cd2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -180,9 +180,15 @@ public class EventHandler {
closeException(context, e); closeException(context, e);
} }
} else { } else {
SelectionKey selectionKey = context.getSelectionKey();
boolean currentlyWriteInterested = SelectionKeyUtils.isWriteInterested(selectionKey);
boolean pendingWrites = context.readyForFlush(); boolean pendingWrites = context.readyForFlush();
SelectionKey selectionKey = context.getSelectionKey();
if (selectionKey == null) {
if (pendingWrites) {
writeException(context, new IllegalStateException("Tried to write to an not yet registered channel"));
}
return;
}
boolean currentlyWriteInterested = SelectionKeyUtils.isWriteInterested(selectionKey);
if (currentlyWriteInterested == false && pendingWrites) { if (currentlyWriteInterested == false && pendingWrites) {
SelectionKeyUtils.setWriteInterested(selectionKey); SelectionKeyUtils.setWriteInterested(selectionKey);
} else if (currentlyWriteInterested && pendingWrites == false) { } else if (currentlyWriteInterested && pendingWrites == false) {