瀏覽代碼

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

* 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
Armin Braun 6 年之前
父節點
當前提交
156047f202
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      libs/nio/src/main/java/org/elasticsearch/nio/EventHandler.java

+ 7 - 1
libs/nio/src/main/java/org/elasticsearch/nio/EventHandler.java

@@ -180,9 +180,15 @@ public class EventHandler {
                 closeException(context, e);
                 closeException(context, e);
             }
             }
         } else {
         } else {
+            boolean pendingWrites = context.readyForFlush();
             SelectionKey selectionKey = context.getSelectionKey();
             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);
             boolean currentlyWriteInterested = SelectionKeyUtils.isWriteInterested(selectionKey);
-            boolean pendingWrites = context.readyForFlush();
             if (currentlyWriteInterested == false && pendingWrites) {
             if (currentlyWriteInterested == false && pendingWrites) {
                 SelectionKeyUtils.setWriteInterested(selectionKey);
                 SelectionKeyUtils.setWriteInterested(selectionKey);
             } else if (currentlyWriteInterested && pendingWrites == false) {
             } else if (currentlyWriteInterested && pendingWrites == false) {