rib commented on code in PR #7088:
URL: https://github.com/apache/opendal/pull/7088#discussion_r2640516654
##########
bindings/java/src/executor.rs:
##########
@@ -129,7 +129,7 @@ pub(crate) fn make_tokio_executor(env: &mut JNIEnv, cores:
usize) -> Result<Exec
move || {
ENV.with(|cell| {
let mut env = vm
- .attach_current_thread_permanently()
+ .attach_current_thread_as_daemon()
Review Comment:
A hang from not using _as_daemon implies you have some code that is using
JavaVM::destroy() / DestroyJavaVM which is probably unsafe / unsound in any
project with RAII types (including global references from the jni crate) that
may result in jni usage after the vm is destroyed.
The most likely reason it appears to hang is because DestroyJavaVM will
block and wait for (non-daemon) jni threads to exit.
Attaching as daemon threads will avoid that blocking but will almost
certainly be completely unsound.
The hang itself indicates that the non-blocking case is unsound because it
implies you have non-daemon threads that are associated with the jni crate
which has RAII types that may trigger JNI usage after the VM has been destroyed.
The safe fix to avoid the blocking would be to have a mechanism to terminate
any jni threads you have (e.g. destroying your tokio runtime + thread pool). Or
don't ever try and destroy the VM (this is a very poorly defined operation).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]