# ElasticSearch failure: Environment is not locked

**URL:** <https://discuss.elastic.co/t/elasticsearch-failure-environment-is-not-locked/182559>\
**Category:** Elasticsearch\
**Created:** [May 24, 2019, 5:29am UTC](https://discuss.elastic.co/t/elasticsearch-failure-environment-is-not-locked/182559 "2019-05-24T05:29:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HPVRNP](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hpvrnp/32/37756_2.png) [@HPVRNP](https://discuss.elastic.co/u/HPVRNP)\
**Post date:** [May 24, 2019, 5:29am UTC](https://discuss.elastic.co/t/elasticsearch-failure-environment-is-not-locked/182559/1 "2019-05-24T05:29:16Z")

</div>

Hi,

Environment:  
OS : Windows 64-bit  
ElasticSearch : 6.6.2  
Java: 1.8.151  
Cluster: Single Node cluster  
Index strategy: Indices are created daily and programmatically  
Shard: Single shard per index and no replication

We have been using elasticsearch for more than a month.  
The machine contains approximately 30 indices (data for 30 days).  
Total size of all the indices is around 100s of GBs.

```auto
[2019-04-19T10:28:40,735][WARN][o.e.e.NodeEnvironment] [Heqvpo8] lock assertion failed
java.io.IOException: The device is not ready
	at sun.nio.ch.FileDispatcherImpl.size0(Native Method) ~[?:?]
	at sun.nio.ch.FileDispatcherImpl.size(FileDispatcherImpl.java:97) ~[?:?]
	at sun.nio.ch.FileChannelImpl.size(FileChannelImpl.java:310) ~[?:?]
	at org.apache.lucene.store.NativeFSLockFactory$NativeFSLock.ensureValid(NativeFSLockFactory.java:182) ~[lucene-core-7.6.0.jar:7.6.0 719cde97f84640faa1e3525690d262946571245f - nknize - 2018-12-07 14:44:20]
	at org.elasticsearch.env.NodeEnvironment.assertEnvIsLocked(NodeEnvironment.java:999) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.env.NodeEnvironment.indexPaths(NodeEnvironment.java:798) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.gateway.MetaStateService.writeIndex(MetaStateService.java:125) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.gateway.GatewayMetaState.applyClusterState(GatewayMetaState.java:176) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.cluster.service.ClusterApplierService.lambda$callClusterStateAppliers$6(ClusterApplierService.java:486) ~[elasticsearch-6.6.2.jar:6.6.2]
	at java.lang.Iterable.forEach(Iterable.java:75) [?:1.8.0_151]
	at org.elasticsearch.cluster.service.ClusterApplierService.callClusterStateAppliers(ClusterApplierService.java:483) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.cluster.service.ClusterApplierService.applyChanges(ClusterApplierService.java:470) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.cluster.service.ClusterApplierService.runTask(ClusterApplierService.java:421) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.cluster.service.ClusterApplierService$UpdateTask.run(ClusterApplierService.java:165) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:660) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:244) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:207) [elasticsearch-6.6.2.jar:6.6.2]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_151]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_151]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151]
[2019-04-19T10:28:40,735][WARN][o.e.e.NodeEnvironment] [Heqvpo8] lock assertion failed
java.io.IOException: The device is not ready
	at sun.nio.ch.FileDispatcherImpl.size0(Native Method) ~[?:?]
	at sun.nio.ch.FileDispatcherImpl.size(FileDispatcherImpl.java:97) ~[?:?]
	at sun.nio.ch.FileChannelImpl.size(FileChannelImpl.java:310) ~[?:?]
	at org.apache.lucene.store.NativeFSLockFactory$NativeFSLock.ensureValid(NativeFSLockFactory.java:182) ~[lucene-core-7.6.0.jar:7.6.0 719cde97f84640faa1e3525690d262946571245f - nknize - 2018-12-07 14:44:20]
	at org.elasticsearch.env.NodeEnvironment.assertEnvIsLocked(NodeEnvironment.java:999) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.env.NodeEnvironment.availableShardPaths(NodeEnvironment.java:817) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.gateway.TransportNodesListGatewayStartedShards.nodeOperation(TransportNodesListGatewayStartedShards.java:120) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.gateway.TransportNodesListGatewayStartedShards.nodeOperation(TransportNodesListGatewayStartedShards.java:61) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.action.support.nodes.TransportNodesAction.nodeOperation(TransportNodesAction.java:138) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.action.support.nodes.TransportNodesAction$NodeTransportHandler.messageReceived(TransportNodesAction.java:259) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.action.support.nodes.TransportNodesAction$NodeTransportHandler.messageReceived(TransportNodesAction.java:255) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler$1.doRun(SecurityServerTransportInterceptor.java:250) [x-pack-security-6.6.2.jar:6.6.2]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.messageReceived(SecurityServerTransportInterceptor.java:308) [x-pack-security-6.6.2.jar:6.6.2]
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:66) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:687) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:759) [elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.6.2.jar:6.6.2]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_151]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_151]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151]
[2019-04-19T10:28:40,739][WARN][o.e.g.MetaStateService] [Heqvpo8] [[ktinspectorlogs-18-04-2019/0mW-XRLvSneko2uxm2cGWg]]: failed to write index state
java.lang.IllegalStateException: environment is not locked
	at org.elasticsearch.env.NodeEnvironment.assertEnvIsLocked(NodeEnvironment.java:1002) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.env.NodeEnvironment.indexPaths(NodeEnvironment.java:798) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.gateway.MetaStateService.writeIndex(MetaStateService.java:125) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.gateway.GatewayMetaState.applyClusterState(GatewayMetaState.java:176) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.cluster.service.ClusterApplierService.lambda$callClusterStateAppliers$6(ClusterApplierService.java:486) ~[elasticsearch-6.6.2.jar:6.6.2]
	at java.lang.Iterable.forEach(Iterable.java:75) [?:1.8.0_151]

Caused by: java.lang.IllegalStateException: environment is not locked

```

---

<div class="post-metadata">

**Author:** ![HPVRNP](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hpvrnp/32/37756_2.png) [@HPVRNP](https://discuss.elastic.co/u/HPVRNP)\
**Post date:** [May 24, 2019, 7:27am UTC](https://discuss.elastic.co/t/elasticsearch-failure-environment-is-not-locked/182559/2 "2019-05-24T07:27:00Z")

</div>

This issue happens every time I restart the machine.  
The workaround is to restart elasticsearch service.

What is the root cause of this error?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [May 24, 2019, 7:32am UTC](https://discuss.elastic.co/t/elasticsearch-failure-environment-is-not-locked/182559/3 "2019-05-24T07:32:18Z")

</div>

> [@HPVRNP](#):
>
> `java.io.IOException: The device is not ready`

It looks like you're starting up Elasticsearch before the storage device is ready.

---

<div class="post-metadata">

**Author:** ![HPVRNP](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hpvrnp/32/37756_2.png) [@HPVRNP](https://discuss.elastic.co/u/HPVRNP)\
**Post date:** [May 24, 2019, 8:46am UTC](https://discuss.elastic.co/t/elasticsearch-failure-environment-is-not-locked/182559/4 "2019-05-24T08:46:57Z")

</div>

The service is running in Auto mode (Windows elastic service). So it tries to start on system boot.

---

<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:** [June 21, 2019, 8:59am UTC](https://discuss.elastic.co/t/elasticsearch-failure-environment-is-not-locked/182559/5 "2019-06-21T08:59:59Z")

</div>

Closed on June 21, 2019, 8:59am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
