]> git.bitcoin.ninja Git - ldk-java/commitdiff
Demonstrate crash by default 2021-12-java-finalize-while-accessible-demo
authorMatt Corallo <git@bluematt.me>
Sun, 12 Dec 2021 06:34:08 +0000 (06:34 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 12 Dec 2021 06:34:08 +0000 (06:34 +0000)
crashy.patch [new file with mode: 0644]
genbindings.sh

diff --git a/crashy.patch b/crashy.patch
new file mode 100644 (file)
index 0000000..c27d47a
--- /dev/null
@@ -0,0 +1,64 @@
+diff --git a/src/main/java/org/ldk/structs/ChannelMonitor.java b/src/main/java/org/ldk/structs/ChannelMonitor.java
+index c9b5444e..6bd1811d 100644
+--- a/src/main/java/org/ldk/structs/ChannelMonitor.java
++++ b/src/main/java/org/ldk/structs/ChannelMonitor.java
+@@ -30,6 +30,7 @@ public class ChannelMonitor extends CommonBase {
+       ChannelMonitor(Object _dummy, long ptr) { super(ptr); }
+       @Override @SuppressWarnings("deprecation")
+       protected void finalize() throws Throwable {
++System.err.println("Finalizing a ChannelMonitor - " + this);
+               super.finalize();
+               if (ptr != 0) { bindings.ChannelMonitor_free(ptr); }
+       }
+diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java
+index 6e90c61..9fcfcfb 100644
+--- a/src/test/java/org/ldk/HumanObjectPeerTest.java
++++ b/src/test/java/org/ldk/HumanObjectPeerTest.java
+@@ -232,12 +232,21 @@ class HumanObjectPeerTestInstance {
+                 @Override
+                 public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id, ChannelMonitorUpdate update, ChannelMonitor data, MonitorUpdateId update_id) {
++                    String key = Arrays.toString(id.to_channel_id());
++System.err.println(data);
++                   byte[] mon_data = data.write();
++                   byte[] mon_data2 = data.write();
++                   byte[] mon_data3 = data.write();
++
++            Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ roundtrip_monitor = UtilMethods.C2Tuple_BlockHashChannelMonitorZ_read(data.write(), keys_interface);
++System.err.println("YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS");
++            assert roundtrip_monitor instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK;
++            ChannelMonitor used_mon = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) roundtrip_monitor).res.get_b();
+                     synchronized (monitors) {
+-                        String key = Arrays.toString(id.to_channel_id());
+-                        assert monitors.put(key, data) != null;
+-                        TwoTuple_OutPointScriptZ res = test_mon_roundtrip(data);
+-                        assert Arrays.equals(res.get_a().get_txid(), id.get_txid());
+-                        assert res.get_a().get_index() == id.get_index();
++                        assert monitors.put(key, used_mon) != null;
++                        //TwoTuple_OutPointScriptZ res = test_mon_roundtrip(data);
++                        //assert Arrays.equals(res.get_a().get_txid(), id.get_txid());
++                        //assert res.get_a().get_index() == id.get_index();
+                     }
+                     return Result_NoneChannelMonitorUpdateErrZ.ok();
+                 }
+@@ -1080,10 +1089,19 @@ public class HumanObjectPeerTest {
+     }
+     @Test
+     public void test_message_handler() throws InterruptedException {
++        new Thread(() -> {
++            while (true) {
++                System.gc();
++                System.runFinalization();
++                try {
++                    Thread.sleep(0, 1);
++                } catch (InterruptedException e) {}
++            }
++        }, "GCForceThread").start();
+         for (int i = 0; i < (1 << 9) - 1; i++) {
+             boolean nice_close =                   (i & (1 << 0)) != 0;
+             boolean use_km_wrapper =               (i & (1 << 1)) != 0;
+-            boolean use_manual_watch =             (i & (1 << 2)) != 0;
++            boolean use_manual_watch =             false;
+             boolean reload_peers =                 (i & (1 << 3)) != 0;
+             boolean break_cross_refs =             (i & (1 << 4)) != 0;
+             boolean use_ignoring_routing_handler = (i & (1 << 5)) != 0;
index 13f4c6c3e1179ef1700a30dccd57510ac72d803c..51193dd81bbcd5e90e28c6a8a9a622bb8d853042 100755 (executable)
@@ -171,6 +171,9 @@ else
        fi
 fi
 
+git apply crashy.patch
+ln -s liblightningjni_debug_*.so liblightningjni.so
+
 echo "Creating TS bindings..."
 mkdir -p ts/{enums,structs}
 rm -f ts/{enums,structs}/*.ts