devopvoid / webrtc-java

WebRTC for desktop platforms running Java
Apache License 2.0
248 stars 60 forks source link

Crash when using a separate class-loader on Windows #49

Closed parg closed 2 years ago

parg commented 2 years ago

I have an application that loads different components using separate "class loaders". When my component is loaded using the system class loader things work great. When loaded via a separate classloader it causes a native crash.

I have reproduced the problem with some minimal classes:

bug.zip

Test2.java creates a peer connection, data channel and offer and loops printing the peer state. This should be packaged into test2.jar.

run_test2.bat invokes Test2 with the required jars on the command line.

Everything runs fine.

Test1.java creates a URLClassLoader with the jars required to run Test2 and loads and runs Test2 via the class loader. This should be packaged into test1.jar.

run_test1.bat invokes Test1

The RTCPeerConnection etc are created but then the JVM crashes while looping to print the peer state.

My guess would be that something in your JNI code is assuming that the system class loader can be used to load some webrtc-specific resource (which it can't as the system class loader doesn't know about it)

devopvoid commented 2 years ago

Thank you very much for the code. Will have a look at it and report back.

parg commented 2 years ago

No problem - it also crashes on Linux so isn't Windows specific (didn't try OSX)

devopvoid commented 2 years ago

Thanks for the report.. made this library more robust :-)

parg commented 2 years ago

Excellent, if you can please give me a heads-up when I can grab a build to test against!

devopvoid commented 2 years ago

If you want, you can test with 0.6.0-SNAPSHOT. Should work with any of supported OS.

parg commented 2 years ago

I grabbed 0.6.0 for testing. Seems to work OK on Windows but on OSX I get the attached crash occasionally - things run fine for a while, I can't figure out anything in particular that is happening when the crash occurs unfortunately :

Thread 147 Crashed:: Thread 0x0x7fbe927bc230 0 libsystem_kernel.dylib 0x00007fff205624ae os_fault_with_payload + 10 1 libsystem_kernel.dylib 0x00007fff2056302f __darwin_check_fd_set_overflow.cold.2 + 31 2 libsystem_kernel.dylib 0x00007fff2054c8e6 __darwin_check_fd_set_overflow + 68 3 libwebrtc-java3645846096757812889.dylib 0x000000003da691e4 0x3d774000 + 3101156 4 libwebrtc-java3645846096757812889.dylib 0x000000003da68ee5 0x3d774000 + 3100389 5 libwebrtc-java3645846096757812889.dylib 0x000000003da6ca04 0x3d774000 + 3115524 6 libwebrtc-java3645846096757812889.dylib 0x000000003da6b7dd 0x3d774000 + 3110877 7 libwebrtc-java3645846096757812889.dylib 0x000000003da6d6dc 0x3d774000 + 3118812 8 libsystem_pthread.dylib 0x00007fff205748fc _pthread_start + 224 9 libsystem_pthread.dylib 0x00007fff20570443 thread_start + 15

https://github.com/devopvoid/webrtc-java/files/7918438/osxcrash.txt