jira-importer opened a new issue, #1225:
URL: https://github.com/apache/httpcomponents-core/issues/1225

   **[Kurtcebe 
Eroglu](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=kurtcebe%20eroglu)**
 opened 
**[HTTPCORE-695](https://issues.apache.org/jira/browse/HTTPCORE-695?redirect=false)**
 and commented
   
   An unhandled `java.nio.channels.CancelledKeyException` in 
AbstractIOReactor#processPendingInterestOps() leads to a shutdown of the 
underlying IOReactor. This is very similar to 
[HTTPCORE-336](https://issues.apache.org/jira/browse/HTTPCORE-336).
   
   This happens regularly under non-reproducible circumstances, producing the 
following stack trace in the logs;
   
   ```
   2021-10-12 00:22:19,326-0400 httpclient-io:thread-1 ERROR anonymous     
[o.a.h.i.nio.client.InternalHttpAsyncClient] I/O reactor terminated abnormally
   org.apache.http.nio.reactor.IOReactorException: I/O dispatch worker 
terminated abnormally
        at 
org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:356)
        at 
org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:221)
        at 
org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
        at java.base/java.lang.Thread.run(Thread.java:834)
   Caused by: java.nio.channels.CancelledKeyException
        at 
java.base/sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:71)
        at 
java.base/sun.nio.ch.SelectionKeyImpl.interestOps(SelectionKeyImpl.java:96)
        at 
org.apache.http.impl.nio.reactor.AbstractIOReactor.processPendingInterestOps(AbstractIOReactor.java:459)
        at 
org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:298)
        at 
org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
        at 
org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)
   ```
   
   The problem happens at `AbstractIOReactor#processPendingInterestOps()`. Even 
if we check `key.isValid()` in the loop before processing, apparently we may 
still observe a `CancelledKeyException` during `key.interestOps(eventMask)`. 
Following patch may help this condition, following from similar check at method 
`processClosedSessions()` ;
   
   ```java
   Index: 
httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
   ===================================================================
   --- 
httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
       (revision 975b373b6e0431ba8f58abe004039f925703a808)
   +++ 
httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
       (date 1636046242908)
   @@ -456,7 +456,11 @@
                final SelectionKey key = entry.getSelectionKey();
                final int eventMask = entry.getEventMask();
                if (key.isValid()) {
   -                key.interestOps(eventMask);
   +                try {
   +                    key.interestOps(eventMask);
   +                } catch (CancelledKeyException ex) {
   +                    // ignore and move on
   +                }
                }
            }
        }
   ```
   
   
   
   ---
   
   **Affects:** 4.4.10
   
   0 votes, 5 watchers
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to