# CancelledKeyException during shutdown

**URL:** <https://discuss.elastic.co/t/cancelledkeyexception-during-shutdown/4367>\
**Category:** Elasticsearch\
**Created:** [May 9, 2011, 12:17am UTC](https://discuss.elastic.co/t/cancelledkeyexception-during-shutdown/4367 "2011-05-09T00:17:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Cook\_2](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@James\_Cook\_2](https://discuss.elastic.co/u/James_Cook_2)\
**Post date:** [May 9, 2011, 12:17am UTC](https://discuss.elastic.co/t/cancelledkeyexception-during-shutdown/4367/1 "2011-05-09T00:17:19Z")

</div>

I am running 0.16.0 and I started getting this exception at shutdown. Just  
wondering if I am maybe shutting down improperly?

20:12:42,904 DEBUG ker #4-1 ket.nio.SelectorUtil: 74 -  
CancelledKeyException raised by a Selector - JDK bug?  
java.nio.channels.CancelledKeyException  
at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:55)  
at sun.nio.ch.SelectionKeyImpl.readyOps(SelectionKeyImpl.java:69)  
at  
sun.nio.ch.KQueueSelectorImpl.updateSelectedKeys(KQueueSelectorImpl.java:105)  
at sun.nio.ch.KQueueSelectorImpl.doSelect(KQueueSelectorImpl.java:74)  
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)  
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:80)  
at  
org.elasticsearch.common.netty.channel.socket.nio.SelectorUtil.select(SelectorUtil.java:38)  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:163)  
at  
org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
at  
org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:680)

I am only calling \_server.close() at the moment. Should I be calling  
close() on any clients also or doing something else?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 9, 2011, 8:49am UTC](https://discuss.elastic.co/t/cancelledkeyexception-during-shutdown/4367/2 "2011-05-09T08:49:45Z")

</div>

No need to worry, seems like netty missed handling this case. Calling close on the node is enough.  
On Monday, May 9, 2011 at 3:17 AM, James Cook wrote:

> I am running 0.16.0 and I started getting this exception at shutdown. Just wondering if I am maybe shutting down improperly?
> 
> 20:12:42,904 DEBUG ker #4-1 ket.nio.SelectorUtil: 74 - CancelledKeyException raised by a Selector - JDK bug?  
> java.nio.channels.CancelledKeyException  
> at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:55)  
> at sun.nio.ch.SelectionKeyImpl.readyOps(SelectionKeyImpl.java:69)  
> at sun.nio.ch.KQueueSelectorImpl.updateSelectedKeys(KQueueSelectorImpl.java:105)  
> at sun.nio.ch.KQueueSelectorImpl.doSelect(KQueueSelectorImpl.java:74)  
> at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)  
> at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:80)  
> at org.elasticsearch.common.netty.channel.socket.nio.SelectorUtil.select(SelectorUtil.java:38)  
> at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:163)  
> at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)  
> at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)  
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> at java.lang.Thread.run(Thread.java:680)
> 
> I am only calling \_server.close() at the moment. Should I be calling close() on any clients also or doing something else?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:06am UTC](https://discuss.elastic.co/t/cancelledkeyexception-during-shutdown/4367/3 "2017-07-06T04:06:39Z")

</div>


