From 4c9df2eb9ea79405e8ffea69967e78d3bbc7e641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Isnard?= Date: Mon, 3 May 2021 13:42:54 +0200 Subject: [PATCH] fix: Keep Tanker object alive in stop() until fully stopped This prevents tanker_destroy from being called during stop(), which causes a cancel (and has triggered bugs in the past). --- tanker-bindings/src/main/kotlin/io/tanker/api/Tanker.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tanker-bindings/src/main/kotlin/io/tanker/api/Tanker.kt b/tanker-bindings/src/main/kotlin/io/tanker/api/Tanker.kt index bbba243..d5cb37c 100644 --- a/tanker-bindings/src/main/kotlin/io/tanker/api/Tanker.kt +++ b/tanker-bindings/src/main/kotlin/io/tanker/api/Tanker.kt @@ -175,7 +175,9 @@ class Tanker(tankerOptions: TankerOptions) { */ fun stop(): TankerFuture { val futurePtr = lib.tanker_stop(tanker) - return TankerFuture(futurePtr, Unit::class.java) + return TankerFuture(futurePtr, Unit::class.java).andThen(TankerCallbackWithKeepAlive(keepAlive = this) { + // Keep the GC from calling tanker_destroy() through the finalizer until stop() is finished + }) } /**