Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

“No locks available” when run sbt cmd

Tags:

java

sbt

to building spark project, I tried to use sbt. The following exception is occured:

java.io.IOException: No locks available
    at sun.nio.ch.FileChannelImpl.lock0(Native Method)
    at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:871)
    at java.nio.channels.FileChannel.tryLock(FileChannel.java:962)
    at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:88)
    at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:81)
    at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:102)
    at xsbt.boot.Using$.withResource(Using.scala:11)
    at xsbt.boot.Using$.apply(Using.scala:10)
    at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:62)
    at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:52)
    at xsbt.boot.Locks$.apply0(Locks.scala:31)
    at xsbt.boot.Locks$.apply(Locks.scala:28)
    at xsbt.boot.Update.apply(Update.scala:100)
    at xsbt.boot.Launch.update(Launch.scala:279)
    at xsbt.boot.Launch.xsbt$boot$Launch$$retrieve$1(Launch.scala:149)
    at xsbt.boot.Launch$$anonfun$3.apply(Launch.scala:157)
    at scala.Option.getOrElse(Option.scala:120)
    at xsbt.boot.Launch.xsbt$boot$Launch$$getAppProvider0(Launch.scala:157)
    at xsbt.boot.Launch$$anon$2.call(Launch.scala:142)
    at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:98)
    at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:81)
    at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:102)
    at xsbt.boot.Using$.withResource(Using.scala:11)
    at xsbt.boot.Using$.apply(Using.scala:10)
    at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:62)
    at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:52)
    at xsbt.boot.Locks$.apply0(Locks.scala:31)
    at xsbt.boot.Locks$.apply(Locks.scala:28)
    at xsbt.boot.Launch.locked(Launch.scala:178)
    at xsbt.boot.Launch.app(Launch.scala:93)
    at xsbt.boot.Launch.app(Launch.scala:91)
    at xsbt.boot.Launch$.run(Launch.scala:51)
    at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:45)
    at xsbt.boot.Launch$.launch(Launch.scala:65)
    at xsbt.boot.Launch$.apply(Launch.scala:16)
    at xsbt.boot.Boot$.runImpl(Boot.scala:31)
    at xsbt.boot.Boot$.main(Boot.scala:20)
    at xsbt.boot.Boot.main(Boot.scala)
Error during sbt execution: java.io.IOException: No locks available

the sbt version i have tried: 0.11.3-2 and 0.13.0 I aslo tried changing the sbt boot dir to avoid permission issues.

Any idea that I'm doing it wrong.

like image 795
DavidPotter Avatar asked Jul 16 '13 12:07

DavidPotter


2 Answers

SBT relies on your jvm's property "user.home" as working directory, and SEEMS acquire locks in there, if your "user.home" point to a NFS directory which didn't install NFS lock service, then you'll get the "No locks available" error.

I've encountered this error several times(another case is maven trying acquire some locks under $HOME/.m2/...). You have two options:

  • Install NFS lock service
  • Tell sbt don't use your directory in NFS, by passing property -Duser.home=/path/in/local/disk. eg.
    • sbt clean compile -Duser.home=/disk1/myhome
like image 82
zhaown Avatar answered Nov 18 '22 17:11

zhaown


By default sbt tried to aquire an exclusive lock when booting or doing dependency resolution. This is to avoid cache corruption, or the deletion of JAR files that another process is using (which can cause some very strange errors).

This locking is not compatible with distributed file systems, usually. Sometimes it even fails on local filesystems with unexpected implementations. Check your FS to see if Java supports locking on it.

You should be able to disable this locking via:

sbt -Dsbt.boot.lock=false

Addtionally, if you have your own sbt.boot.properties file, you need the following:

[boot]
lock: false

This will disable the locking feature inside the launcher, which in-turn disables locking for all of sbt projects which use this feature. AFAIK this means everything in sbt, although some plugins may be directly using the JDK locking APIs.

like image 45
jsuereth Avatar answered Nov 18 '22 19:11

jsuereth