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

Multithreading brokes memory? #3846

Open
catap opened this issue Mar 18, 2024 · 4 comments
Open

Multithreading brokes memory? #3846

catap opened this issue Mar 18, 2024 · 4 comments
Labels

Comments

@catap
Copy link
Contributor

catap commented Mar 18, 2024

Here an example of test program which uses libuv to implement network and timers.

This program is very CPU and memory intensive and produces some memory footpring.

When I run it without multithreading everything works fine.

With multithreading (and UV loop is running in dedicated thread) it start to have a random crashes.

For example with Boehm GC and commented all stdlib.free for dynamic memory (yep, it leaks):

Program received signal SIGSEGV, Segmentation fault.
[Switching to thread 363500]
0x00000e9db95e2089 in _SM39java.util.concurrent.ConcurrentHashMap$D5tabAtLAL43java.util.concurrent.ConcurrentHashMap$Node_iL43java.util.concurrent.ConcurrentHashMap$NodeEO () from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
(gdb) bt
#0  0x00000e9db95e2089 in _SM39java.util.concurrent.ConcurrentHashMap$D5tabAtLAL43java.util.concurrent.ConcurrentHashMap$Node_iL43java.util.concurrent.ConcurrentHashMap$NodeEO () from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#1  0x00000e9db95df7e3 in _SM38java.util.concurrent.ConcurrentHashMapD15computeIfAbsentL16java.lang.ObjectL27java.util.function.FunctionL16java.lang.ObjectEO () from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#2  0x00000e9db965a7ca in _SM37scala.scalanative.runtime.StackTrace$D17currentStackTraceLAL27java.lang.StackTraceElement_EO ()
   from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#3  0x00000e9db9654728 in _SM19java.lang.ThrowableD16fillInStackTraceL19java.lang.ThrowableEO ()
   from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#4  0x00000e9db96b0ceb in _SM45pt.kcry.cryptosystem.network.UvRemote$$anon$1D11applyOrElseL16java.lang.ObjectL15scala.Function1L16java.lang.ObjectEO ()
   from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#5  0x00000e9db970e8dd in _SM23scala.concurrent.FutureD18$anonfun$andThen$1L21scala.PartialFunctionL33scala.concurrent.ExecutionContextL14scala.util.TryL14scala.util.TryEPT23scala.concurrent.Future () from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#6  0x00000e9db970f49a in _SM34scala.concurrent.Future$$Lambda$12D5applyL16java.lang.ObjectL16java.lang.ObjectEO ()
   from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#7  0x00000e9db969badc in _SM44scala.concurrent.impl.Promise$TransformationD3runuEO ()
   from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#8  0x00000e9db95ea059 in _SM33java.util.concurrent.ForkJoinTaskD6doExeciEO ()
   from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#9  0x00000e9db95e8fff in _SM43java.util.concurrent.ForkJoinPool$WorkQueueD12topLevelExecL33java.util.concurrent.ForkJoinTaskL43java.util.concurrent.ForkJoinPool$WorkQueueuEO () from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#10 0x00000e9db95e7a70 in _SM33java.util.concurrent.ForkJoinPoolD4scanL43java.util.concurrent.ForkJoinPool$WorkQueueiiiEPT33java.util.concurrent.ForkJoinPool () from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#11 0x00000e9db95ea3a6 in _SM41java.util.concurrent.ForkJoinWorkerThreadD3runuEO ()
   from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#12 0x00000e9db96593f9 in _SM39scala.scalanative.runtime.NativeThread$D16threadEntryPointL38scala.scalanative.runtime.NativeThreaduEPT39scala.scalanative.runtime.NativeThread$ () from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#13 0x00000e9db96596ab in _SM39scala.scalanative.runtime.NativeThread$D24threadRoutine$$anonfun$1L28scala.scalanative.unsafe.PtrL28scala.scalanative.unsafe.PtrEPT39scala.scalanative.runtime.NativeThread$ () from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#14 0x00000e9db9659718 in _SM49scala.scalanative.runtime.NativeThread$$$Lambda$1G17$extern$forwarder ()
   from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#15 0x00000e9db979c708 in ProxyThreadStartRoutine () from /home/catap/Projects/Kcrypt/cryptosystem/sandbox/native/target/scala-3.4.0/sandbox
#16 0x00000ea0b2839f42 in _rthread_start (v=Unhandled dwarf expression opcode 0xa3
) at /usr/src/lib/librthread/rthread.c:96
#17 0x00000e9feca50f4a in __tfork_thread () at /usr/src/lib/libc/arch/amd64/sys/tfork_thread.S:87
#18 0x00000e9feca50f4a in __tfork_thread () at /usr/src/lib/libc/arch/amd64/sys/tfork_thread.S:87
Previous frame identical to this frame (corrupt stack?)
(gdb)

P.S. I'm using 0.5.0-RC2

@WojciechMazur
Copy link
Contributor

Thank you for the report. Can you also give us a hint about the config used for compilation, especially releaseMode and LTO. Does this issue exist also in the other GCs?
It feels like it can be related to #3804 and the SIGSEGV might again be raised due to stack overflow

@catap
Copy link
Contributor Author

catap commented Mar 18, 2024

@WojciechMazur I uses default settings and only switched releaseFast. Yes, this application crashes with all GCs which includes none.

Anyway, I still do not roll out possibility that my code is bad and brokes it, I'm reviewing and rewriting it, but it crashes the same way, and this aplication depends on random numbers and uses a lot of them, and each start has different behaviour which include different amount of network traffic, packet size and so on.

=> issue inside SN is quite possible, but I not 100% sure yet, need more time to confirm it.

@catap
Copy link
Contributor Author

catap commented Apr 5, 2024

I finish to rewriting my code to be thread safe and multithreading ready.

Now it fails inside some scala level allocation.

So, I almsot 100% sure that it isn't C-level, and it is something else.

@catap
Copy link
Contributor Author

catap commented Apr 6, 2024

Well, without withMode(Mode.releaseFast) and any other settings the test program had succefully finished. Once. From three attempt. Othertimes it had some deadlocks inside futures which is possible to related to #3848.

Also, under gdb it brokes stack trace and prints different output for bt and thread apply all bt.

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

No branches or pull requests

2 participants