Hi Jakob, 

Would be interesting to understand why  __vcl_worker_index is -1. Ideally when 
constructor creates the app, it should initialize the first worker. Does that 
initialize appropriately?

Regards, 
Florin

> On Jul 10, 2026, at 1:19 AM, Jakob Lövhall via lists.fd.io 
> <[email protected]> wrote:
> 
> Hi,
> 
> I tried running VPP with its LD_PRELOAD library on a Java app.
> What I found was that it will segfault if the JVM encounters some kind of 
> issue, for example not finding the main class to run.
> The segfault happens in vcl_worker_cleanup  coming from vppcom_app_exit, it 
> looks like this is due to indexing issues when __vcl_worker_index is -1.
> 
> Here is a suggestion for patch to avoid it. Please consider it and add test 
> coverage for it.
> 
> ```
> diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c
> index 70d2674f9..873204945 100644
> --- a/src/vcl/vppcom.c
> +++ b/src/vcl/vppcom.c
> @@ -1438,6 +1438,11 @@ vppcom_app_exit (void)
>  {
>    if (!pool_elts (vcm->workers))
>      return;
> +
> +  /* exiting thread never used vcl */
> +  if (vcl_get_worker_index () == ~0)
> +    return;
> +
>    vcl_worker_cleanup (vcl_worker_get_current (), 1 /* notify vpp */ );
>    vcl_set_worker_index (~0);
>    vcl_elog_stop (vcm);
> ```
> 
> 
> 
> This is what the segfault backtrace looks like in gdb
> 
> ```
> Error: Could not find or load main class MainClass
> Caused by: java.lang.ClassNotFoundException: MainClass
> [Thread 0x7fff4ffff6c0 (LWP 1119246) exited]
> [Thread 0x7fff641f96c0 (LWP 1119243) exited]
> [Thread 0x7fff642fa6c0 (LWP 1119242) exited]
> [Thread 0x7fff66b9d6c0 (LWP 1119240) exited]
> 
> Thread 11 "VM Thread" received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x7fff4fefe6c0 (LWP 1119247)]
> vcl_worker_cleanup (wrk=wrk@entry=0x853fe7bd0140, 
> notify_vpp=notify_vpp@entry=1 '\001') at vpp/src/vcl/vcl_private.c:123
> warning: 123 vpp/src/vcl/vcl_private.c: No such file or directory
> (gdb) bt
> #0  vcl_worker_cleanup (wrk=wrk@entry=0x853fe7bd0140, 
> notify_vpp=notify_vpp@entry=1 '\001') at vpp/src/vcl/vcl_private.c:123
> #1  0x00007ffff7d6ffb6 in vppcom_app_exit () at vpp/src/vcl/vppcom.c:1441
> #2  0x00007ffff7dec231 in __cxa_finalize () from /lib64/libc.so 
> <http://libc.so/>.6
> #3  0x00007ffff7d6e1b7 in __do_global_dtors_aux () from 
> /tmp/vpp_files/lib64/libvppcom.so <http://libvppcom.so/>.26.10
> #4  0x00007ffff7fc1a50 in ?? ()
> #5  0x00007ffff7fc90e2 in _dl_call_fini (closure_map=0x7fff4fefd5a0, 
> closure_map@entry=0x7ffff7fc1a50) at dl-call_fini.c:43
> #6  0x00007ffff7fcd370 in _dl_fini () at dl-fini.c:120
> #7  0x00007ffff7dec7b1 in __run_exit_handlers () from /lib64/libc.so 
> <http://libc.so/>.6
> #8  0x00007ffff7dec880 in exit () from /lib64/libc.so <http://libc.so/>.6
> #9  0x00007fffa9880c79 in os::exit(int) () from 
> /home/<user>/.sdkman/candidates/java/25.0.3-tem/lib/server/libjvm.so 
> <http://libjvm.so/>
> #10 0x00007fffa942104c in vm_direct_exit(int) () from 
> /home/<user>/.sdkman/candidates/java/25.0.3-tem/lib/server/libjvm.so 
> <http://libjvm.so/>
> #11 0x00007fffa9c96a67 in VM_Operation::evaluate() () from 
> /home/<user>/.sdkman/candidates/java/25.0.3-tem/lib/server/libjvm.so 
> <http://libjvm.so/>
> #12 0x00007fffa9c9a0a2 in VMThread::evaluate_operation(VM_Operation*) () from 
> /home/<user>/.sdkman/candidates/java/25.0.3-tem/lib/server/libjvm.so 
> <http://libjvm.so/>
> #13 0x00007fffa9c9acd7 in VMThread::inner_execute(VM_Operation*) () from 
> /home/<user>/.sdkman/candidates/java/25.0.3-tem/lib/server/libjvm.so 
> <http://libjvm.so/>
> #14 0x00007fffa9c9af97 in VMThread::run() () from 
> /home/<user>/.sdkman/candidates/java/25.0.3-tem/lib/server/libjvm.so 
> <http://libjvm.so/>
> #15 0x00007fffa9bf842f in Thread::call_run() () from 
> /home/<user>/.sdkman/candidates/java/25.0.3-tem/lib/server/libjvm.so 
> <http://libjvm.so/>
> #16 0x00007fffa9875b16 in thread_native_entry(Thread*) () from 
> /home/<user>/.sdkman/candidates/java/25.0.3-tem/lib/server/libjvm.so 
> <http://libjvm.so/>
> #17 0x00007ffff7e3ea7f in start_thread () from /lib64/libc.so 
> <http://libc.so/>.6
> #18 0x00007ffff7eaf4fc in clone3 () from /lib64/libc.so <http://libc.so/>.6
> ```
> 
> I created a minimal reproducer with Java. Which was just HelloWorld and then 
> misspell the main class such that it cannot be found, but I see that I am not 
> allowed to attach tar.gz files. The reproducer stays with me for now. 
> Hopefully you can reproduce it on your own.
> 
> Thanks,
> Jakob
> 
> 

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#27104): https://lists.fd.io/g/vpp-dev/message/27104
Mute This Topic: https://lists.fd.io/mt/120203465/21656
Group Owner: [email protected]
Unsubscribe: https://lists.fd.io/g/vpp-dev/leave/14379924/21656/631435203/xyzzy 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to