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

Connection leak when coroutine canceled #159

Closed
namjug-kim opened this issue Jan 4, 2023 · 3 comments
Closed

Connection leak when coroutine canceled #159

namjug-kim opened this issue Jan 4, 2023 · 3 comments

Comments

@namjug-kim
Copy link

namjug-kim commented Jan 4, 2023

kotlin-jdsl converts Uni to Coroutine through 'Mutiny#awaitSuspended'.
Look more closely here, the awaitSuspend function implemented by suspendCancellableCoroutine and invoke UniSubscriber#cancel when coroutine canceled.

However, hiberante-reactive MutinySessionFactoryImpl does not provide close process for cancel.

private<S extends Mutiny.Closeable, T> Uni<T> withSession(
          Uni<S> sessionUni,
          Function<S, Uni<T>> work,
          Context.Key<S> contextKey) {
        return sessionUni.chain( session -> Uni.createFrom().voidItem()
              .invoke( () -> context.put( contextKey, session ) )
              .chain( () -> work.apply( session ) )
              .eventually( () -> context.remove( contextKey ) )
              .eventually(session::close)
        );
}

below code not be executed when Uni(withSession) is canceled and Session not closed forever.

.eventually( () -> context.remove( contextKey ) )
.eventually(session::close)

Im not sure this hibernate-reactive session behavior is intended :(
related issue in hibernate-reactive issue

To use current version(1.1.9.Final) hibernate-reactive session, Uni must be converted to coroutine using suspendCoroutine instead of suspendCancellableCoroutine.

suspend fun <T> Uni<T>.awaitSingle() = suspendCoroutine<T> { continuation ->
    subscribe().with(
        { item -> continuation.resume(item) },
        { failure -> continuation.resumeWithException(failure) }
    )
}
@namjug-kim
Copy link
Author

This issue will be fixed in Hibernate-reactive 😀

With current version avoid using waitSuspending to prevent cancellation if call withSession outside of the vertx context.

@cj848
Copy link
Collaborator

cj848 commented Jan 5, 2023

I checked the issue link. thanks. Even if mutiny is fixed, it seems to be solved. Since jdsl reactive doesn't enforce hibernate reactive/mutiny version, it seems that the problem can go away if the version goes up. We will not take action right away, and please comment when the version is up.

@cj848
Copy link
Collaborator

cj848 commented Sep 5, 2023

With the change to jdsl 3.0, the wrapper that creates the session and the wrapper responsible for execution are also no longer provided. For more details, please refer to the https://kotlin-jdsl.gitbook.io/docs/ document and issue #446.

@cj848 cj848 closed this as completed Sep 5, 2023
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