novitski / bitcoinj

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

NetworkParameters construction is not thread safe #549

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Attempting to use the static get() methods on different NetworkParameters 
classes in parallel can deadlock, because the locking is too complicated and 
Script attempts to grab a params during its clinit. Here Thread-6 is stopped 
(though the stack trace doesn't show it) on a Script.writeBytes call that it 
can't enter because Thread-7 is inside Script.<clinit>, and Thread-7 can't 
proceed because it's waiting for TestNet3Params to become available which is 
being constructed by Thread-6.

"Thread-7" #17 prio=5 os_prio=31 tid=0x00007fe99893c800 nid=0xbf03 waiting for 
monitor entry [0x000000012acc8000]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at com.google.bitcoin.params.TestNet3Params.get(TestNet3Params.java:60)
    - waiting to lock <0x00000007401c5ab8> (a java.lang.Class for com.google.bitcoin.params.TestNet3Params)
    at com.google.bitcoin.core.Address.getParameters(Address.java:127)
    at com.google.bitcoin.core.Address.isP2SHAddress(Address.java:112)
    at com.google.bitcoin.script.ScriptBuilder.createOutputScript(ScriptBuilder.java:68)
    at com.google.bitcoin.script.Script.<clinit>(Script.java:148)
    at com.google.bitcoin.core.NetworkParameters.createGenesis(NetworkParameters.java:110)
    at com.google.bitcoin.core.NetworkParameters.<init>(NetworkParameters.java:96)
    at com.google.bitcoin.params.TestNet2Params.<init>(TestNet2Params.java:30)
    at com.google.bitcoin.params.RegTestParams.<init>(RegTestParams.java:32)
    at com.google.bitcoin.params.RegTestParams.get(RegTestParams.java:63)
    - locked <0x0000000740134d40> (a java.lang.Class for com.google.bitcoin.params.RegTestParams)

"Thread-6" #16 prio=5 os_prio=31 tid=0x00007fe99a15f800 nid=0xbd03 in 
Object.wait() [0x000000012abc5000]
   java.lang.Thread.State: RUNNABLE
    at com.google.bitcoin.core.NetworkParameters.createGenesis(NetworkParameters.java:110)
    at com.google.bitcoin.core.NetworkParameters.<init>(NetworkParameters.java:96)
    at com.google.bitcoin.params.TestNet3Params.<init>(TestNet3Params.java:31)
    at com.google.bitcoin.params.TestNet3Params.get(TestNet3Params.java:61)
    - locked <0x00000007401c5ab8> (a java.lang.Class for com.google.bitcoin.params.TestNet3Params)
    at com.google.bitcoin.core.NetworkParameters.fromPmtProtocolID(NetworkParameters.java:215)
    at com.google.bitcoin.protocols.payments.PaymentSession.parsePaymentRequest(PaymentSession.java:397)

Original issue reported on code.google.com by mh.in.en...@gmail.com on 25 Apr 2014 at 10:44

GoogleCodeExporter commented 9 years ago
This is most likely fixed by https://github.com/bitcoinj/bitcoinj/pull/87

Original comment by qert...@gmail.com on 4 Jun 2014 at 6:47

GoogleCodeExporter commented 9 years ago

Original comment by mh.in.en...@gmail.com on 29 Jun 2014 at 11:44