Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completing Backpressure Deferrable Deadlocks #109

Open
rsteppac opened this issue Dec 10, 2023 · 2 comments
Open

Completing Backpressure Deferrable Deadlocks #109

rsteppac opened this issue Dec 10, 2023 · 2 comments

Comments

@rsteppac
Copy link

rsteppac commented Dec 10, 2023

Kotlin version: 1.9.21
Native Platform build: linuxX64
OS: Ubuntu 23.10

I tried the "Simple Example" from the README.MD, but the backpressure communication via the CompletableDeferred<Int> seems the get deadlocked and the simple example never terminates. Triggering the kill signal (SIGINT or SITGERM) gets correctly communicated to the arrow.continuations.unsafe.Unsafe#onShutdown hook, but the shutdown hook never returns from the call to BACKPRESSURE.complete(..) and the waiting signal handler never gets released. Providing a timeout to arrow.continuations.SuspendAppKt#SuspendApp has no effect.

@nomisRev
Copy link
Member

Hey @rsteppac,

Thank you for this report! This might be related to #70. Strange that it works fine on MacOS given that it uses the same Kotlin/Native code.

Could you share the snippet you used to produce this?

@rsteppac
Copy link
Author

rsteppac commented Dec 11, 2023

@nomisRev , I have published a demonstrator here: https://github.com/rsteppac/kotlin-signalhandler-demo/tree/develop

I started out with suspendapp as a dependency, but for easier debugging (println everywhere) I copied the two source files required for a linux native build into my demonstrator repo.

When I run the executable and then try to interrupt it, then I get this output:

$ ./kotlin-signalhandler-demo-0.0.1-SNAPSHOT.kexe 
Unsafe.onShutdown: GlobalScope.launch
Unsafe.onShutdown: signal(SIGTERM, SignalHandler)
Unsafe.onShutdown: signal(SIGINT, SignalHandler)
Unsafe.onShutdown: return {}
App Started!  Waiting until asked to shutdown.
Unsafe.onShutdown: GlobalScope.launch: SIGNAL.await()
Ping
Ping
Ping
^CSignalHandler: signal code = 2
SignalHandler: BACKPRESSURE.await()
Unsafe.onShutdown: GlobalScope.launch: SIGNAL.await(): code = 2
Unsafe.onShutdown: GlobalScope.launch: runCatching { block() }
kotlinx.coroutines.JobCancellationException: LazyStandaloneCoroutine was cancelled; job=LazyStandaloneCoroutine{Cancelling}@6cb3c0e0
Cleaning up App... will take 2s...
Done cleaning up. Will release app to exit
Unsafe.onShutdown: GlobalScope.launch: runCatching { block() }: res = Success(kotlin.Unit)
Unsafe.onShutdown: GlobalScope.launch: BACKPRESSURE.complete
Killed

The second to last line is printed before the call to BACKPRESSURE.complete(res.fold({ code }, { -1 })).
The last line of the output is the result of sending a SIGKILL to the stuck process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants