danielmcclure / bitcoinj

Automatically exported from code.google.com/p/bitcoinj
Apache License 2.0
0 stars 1 forks source link

SPVBlockStore: ErrnoException: fcntl failed: EAGAIN (Try again) #584

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Bitcoinj 0.12. When instantiating an SPVBlockStore, sometimes I get the 
following exception. The line 111 in the source is

fileLock = channel.tryLock();

The exception suggests to try again. Indeed, the issue is usually not 
reproducable: just start the app again and it works.

I wonder, can we do anything here, like immediately trying again?

java.lang.Error: blockstore cannot be created
at 
de.schildbach.wallet.service.BlockchainServiceImpl.onCreate(BlockchainServiceImp
l.java:635)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2558)
at android.app.ActivityThread.access$1800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.bitcoinj.store.BlockStoreException: java.io.IOException: fcntl 
failed: EAGAIN (Try again)
at org.bitcoinj.store.SPVBlockStore.<init>(SPVBlockStore.java:138)
at 
de.schildbach.wallet.service.BlockchainServiceImpl.onCreate(BlockchainServiceImp
l.java:611)
... 11 more
Caused by: java.io.IOException: fcntl failed: EAGAIN (Try again)
at java.nio.FileChannelImpl.basicLock(FileChannelImpl.java:123)
at java.nio.FileChannelImpl.tryLock(FileChannelImpl.java:177)
at java.nio.channels.FileChannel.tryLock(FileChannel.java:587)
at org.bitcoinj.store.SPVBlockStore.<init>(SPVBlockStore.java:111)
... 12 more
Caused by: libcore.io.ErrnoException: fcntl failed: EAGAIN (Try again)
at libcore.io.Posix.fcntlFlock(Native Method)
at libcore.io.ForwardingOs.fcntlFlock(ForwardingOs.java:54)
at java.nio.FileChannelImpl.basicLock(FileChannelImpl.java:121)
... 15 more

Cause:

org.bitcoinj.store.BlockStoreException: java.io.IOException: fcntl failed: 
EAGAIN (Try again)
at org.bitcoinj.store.SPVBlockStore.<init>(SPVBlockStore.java:138)
at 
de.schildbach.wallet.service.BlockchainServiceImpl.onCreate(BlockchainServiceImp
l.java:611)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2558)
at android.app.ActivityThread.access$1800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.IOException: fcntl failed: EAGAIN (Try again)
at java.nio.FileChannelImpl.basicLock(FileChannelImpl.java:123)
at java.nio.FileChannelImpl.tryLock(FileChannelImpl.java:177)
at java.nio.channels.FileChannel.tryLock(FileChannel.java:587)
at org.bitcoinj.store.SPVBlockStore.<init>(SPVBlockStore.java:111)
... 12 more
Caused by: libcore.io.ErrnoException: fcntl failed: EAGAIN (Try again)
at libcore.io.Posix.fcntlFlock(Native Method)
at libcore.io.ForwardingOs.fcntlFlock(ForwardingOs.java:54)
at java.nio.FileChannelImpl.basicLock(FileChannelImpl.java:121)
... 15 more

Cause:

java.io.IOException: fcntl failed: EAGAIN (Try again)
at java.nio.FileChannelImpl.basicLock(FileChannelImpl.java:123)
at java.nio.FileChannelImpl.tryLock(FileChannelImpl.java:177)
at java.nio.channels.FileChannel.tryLock(FileChannel.java:587)
at org.bitcoinj.store.SPVBlockStore.<init>(SPVBlockStore.java:111)
at 
de.schildbach.wallet.service.BlockchainServiceImpl.onCreate(BlockchainServiceImp
l.java:611)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2558)
at android.app.ActivityThread.access$1800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: fcntl failed: EAGAIN (Try again)
at libcore.io.Posix.fcntlFlock(Native Method)
at libcore.io.ForwardingOs.fcntlFlock(ForwardingOs.java:54)
at java.nio.FileChannelImpl.basicLock(FileChannelImpl.java:121)
... 15 more

Cause:

libcore.io.ErrnoException: fcntl failed: EAGAIN (Try again)
at libcore.io.Posix.fcntlFlock(Native Method)
at libcore.io.ForwardingOs.fcntlFlock(ForwardingOs.java:54)
at java.nio.FileChannelImpl.basicLock(FileChannelImpl.java:121)
at java.nio.FileChannelImpl.tryLock(FileChannelImpl.java:177)
at java.nio.channels.FileChannel.tryLock(FileChannel.java:587)
at org.bitcoinj.store.SPVBlockStore.<init>(SPVBlockStore.java:111)
at 
de.schildbach.wallet.service.BlockchainServiceImpl.onCreate(BlockchainServiceImp
l.java:611)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2558)
at android.app.ActivityThread.access$1800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

Original issue reported on code.google.com by andreas....@gmail.com on 19 Oct 2014 at 9:03

GoogleCodeExporter commented 9 years ago
Did this really only start with 0.12? The block store code has not changed for 
a long time.

What I think this means is, somehow the app is still running in another 
process. I thought Android would not do this - if there was a process for the 
app, it would always be reused. But perhaps in some cases, the OS now spins up 
two processes for the same app, perhaps if one is hung or in the process of 
shutting down. You do shut down BlockStore when the service is terminating, 
right?

But basically this means "we cannot start right now, because another copy of 
the app might be using the block store file". Handling this automatically 
inside bitcoinj might be possible but it's not ideal because on other platforms 
the right thing to do here is often to tell the user "The app is already 
running, sorry" or to send a message to the running app saying "bring yourself 
to the front" etc. 

Original comment by mh.in.en...@gmail.com on 20 Oct 2014 at 11:49

GoogleCodeExporter commented 9 years ago
Sorry, it's not new to 0.12. Yes I do "blockStore.close();"

Original comment by andreas....@gmail.com on 20 Oct 2014 at 12:07

GoogleCodeExporter commented 9 years ago
For now, you could try catching the exception, sleeping for a second, and then 
indeed trying to open the block store again. See if that makes the exceptions 
go away. Give up after one or two attempts though.

Original comment by mh.in.en...@gmail.com on 20 Oct 2014 at 1:00