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

malloc(): unaligned tcache chunk detected from roc-htmx-playground using basic-webserver #81

Open
gree7 opened this issue Nov 28, 2024 · 2 comments

Comments

@gree7
Copy link

gree7 commented Nov 28, 2024

When testing https://github.com/lukewilliamboswell/roc-htmx-playground (which uses basic-web), the variant working with the current Roc is in lukewilliamboswell/roc-htmx-playground#9, I hit this error:

$ DB_PATH=test.db roc run --linker=legacy src/main.roc
Listening on <http://127.0.0.1:8000>
2024-11-27T11:24:25Z Get /
2024-11-27T11:24:25Z Get /bootstrap.min.css
2024-11-27T11:24:25Z Get /styles.css
2024-11-27T11:24:25Z Get /bootstrap.bundle.min.js
2024-11-27T11:24:25Z Get /htmx.min.js
2024-11-27T11:24:25Z Get /site.js
2024-11-27T11:24:27Z Get /treeview
2024-11-27T11:24:27Z Get /bigTask
2024-11-27T11:24:29Z Get /bigTask?page=2&items=25
2024-11-27T11:24:31Z Get /bigTask?page=3&items=25
2024-11-27T11:24:33Z Get /bigTask?page=4&items=25
2024-11-27T11:24:34Z Get /bigTask?page=2&items=25
malloc(): unaligned tcache chunk detected

I saw the error only at the /bigTask?... requests and the error is happening randomly, but at least on my machine always until 5th request on the /bigTask?....

The run with Valgrind looked like this:

$ DB_PATH=test.db valgrind src/main
==3385473== Memcheck, a memory error detector
==3385473== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==3385473== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==3385473== Command: src/main
==3385473==
==3385473== posix_memalign() invalid size value: 0
==3385473==    at 0x484CA38: posix_memalign (vg_replace_malloc.c:2226)
==3385473==    by 0x273990: rust_main (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x48D5E07: (below main) (libc_start_call_main.h:58)
==3385473==
Listening on <http://127.0.0.1:8000>
2024-11-28T09:40:05Z Get /
2024-11-28T09:40:06Z Get /bootstrap.min.css
2024-11-28T09:40:06Z Get /bootstrap.bundle.min.js
2024-11-28T09:40:06Z Get /styles.css
2024-11-28T09:40:06Z Get /htmx.min.js
2024-11-28T09:40:06Z Get /site.js
2024-11-28T09:40:06Z Get /favicon.ico
404 NotFound /favicon.ico
2024-11-28T09:40:07Z Get /bigTask
2024-11-28T09:40:10Z Get /bigTask?page=2&items=25
==3385473== Thread 20 tokio-runtime-w:
==3385473== Invalid read of size 8
==3385473==    at 0x222789: decrement_refcounted_ptr_8 (roc_app:0)
==3385473==    by 0x22277D: ??? (roc_app:0)
==3385473==    by 0x229287: ??? (roc_app:0)
==3385473==    by 0x1C0D18: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3385473==    by 0x1ECAD1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3385473==    by 0x218289: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3385473==    by 0x1E7D02: _158_3fe74881edf546beefa6734056b1899c37505b1c34fcce49bbd7b44b157595 (roc_app:0)
==3385473==    by 0x22C6CD: roc__forHost_2_caller (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x29A7ED: tokio::runtime::task::raw::poll (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E762D: std::sys_common::backtrace::__rust_begin_short_backtrace (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E736E: core::ops::function::FnOnce::call_once{{vtable.shim}} (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E3ADA: call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> (boxed.rs:2022)
==3385473==    by 0x2E3ADA: call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> (boxed.rs:2022)
==3385473==    by 0x2E3ADA: std::sys::pal::unix::thread::Thread::new::thread_start (thread.rs:108)
==3385473==  Address 0x77720a0 is 0 bytes inside a block of size 32 free'd
==3385473==    at 0x48478EF: free (vg_replace_malloc.c:989)
==3385473==    by 0x2227CA: decrement_refcounted_ptr_8 (roc_app:0)
==3385473==    by 0x22277D: ??? (roc_app:0)
==3385473==    by 0x1A20BA: Controllers.BigTask_15_36cf1b423d96d0d1f556ed298e83394497cd597c20b08eba5512c2685cd67751 (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x1C46BD: Task_46_c436285c5b59d7df49ab96ad8476bdb7c10421fe2225ff48721cb48682ff451 (roc_app:0)
==3385473==    by 0x1CCDFE: Task_46_28ea24f1682fb667c3fb23a9dbc02f29e624f88b5aca38a345144704a3139a (roc_app:0)
==3385473==    by 0x1FF9B2: Task_46_ee6d8d949dc3617ea48fd44bd0c8f21be51d3676b1b3bdfdfcf8f559e4e0272f (roc_app:0)
==3385473==    by 0x222172: Task_46_1f3cd98ac177094c9632f9c81aa71556d2feacfd911d3d139427ec94325c8 (roc_app:0)
==3385473==    by 0x1C0D04: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3385473==    by 0x1ECAD1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3385473==    by 0x218289: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3385473==    by 0x1E7D02: _158_3fe74881edf546beefa6734056b1899c37505b1c34fcce49bbd7b44b157595 (roc_app:0)
==3385473==  Block was alloc'd at
==3385473==    at 0x48447A8: malloc (vg_replace_malloc.c:446)
==3385473==    by 0x2B074D: <roc_std::roc_str::RocStr as core::convert::From<&str>>::from (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x29A5CA: tokio::runtime::task::raw::poll (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E762D: std::sys_common::backtrace::__rust_begin_short_backtrace (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E736E: core::ops::function::FnOnce::call_once{{vtable.shim}} (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E3ADA: call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> (boxed.rs:2022)
==3385473==    by 0x2E3ADA: call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> (boxed.rs:2022)
==3385473==    by 0x2E3ADA: std::sys::pal::unix::thread::Thread::new::thread_start (thread.rs:108)
==3385473==    by 0x494439C: start_thread (pthread_create.c:447)
==3385473==    by 0x49C92A3: clone (clone.S:100)
==3385473==
==3385473== Invalid write of size 8
==3385473==    at 0x2227AA: decrement_refcounted_ptr_8 (roc_app:0)
==3385473==    by 0x22277D: ??? (roc_app:0)
==3385473==    by 0x229287: ??? (roc_app:0)
==3385473==    by 0x1C0D18: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3385473==    by 0x1ECAD1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3385473==    by 0x218289: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3385473==    by 0x1E7D02: _158_3fe74881edf546beefa6734056b1899c37505b1c34fcce49bbd7b44b157595 (roc_app:0)
==3385473==    by 0x22C6CD: roc__forHost_2_caller (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x29A7ED: tokio::runtime::task::raw::poll (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E762D: std::sys_common::backtrace::__rust_begin_short_backtrace (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E736E: core::ops::function::FnOnce::call_once{{vtable.shim}} (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E3ADA: call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> (boxed.rs:2022)
==3385473==    by 0x2E3ADA: call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> (boxed.rs:2022)
==3385473==    by 0x2E3ADA: std::sys::pal::unix::thread::Thread::new::thread_start (thread.rs:108)
==3385473==  Address 0x77720a0 is 0 bytes inside a block of size 32 free'd
==3385473==    at 0x48478EF: free (vg_replace_malloc.c:989)
==3385473==    by 0x2227CA: decrement_refcounted_ptr_8 (roc_app:0)
==3385473==    by 0x22277D: ??? (roc_app:0)
==3385473==    by 0x1A20BA: Controllers.BigTask_15_36cf1b423d96d0d1f556ed298e83394497cd597c20b08eba5512c2685cd67751 (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x1C46BD: Task_46_c436285c5b59d7df49ab96ad8476bdb7c10421fe2225ff48721cb48682ff451 (roc_app:0)
==3385473==    by 0x1CCDFE: Task_46_28ea24f1682fb667c3fb23a9dbc02f29e624f88b5aca38a345144704a3139a (roc_app:0)
==3385473==    by 0x1FF9B2: Task_46_ee6d8d949dc3617ea48fd44bd0c8f21be51d3676b1b3bdfdfcf8f559e4e0272f (roc_app:0)
==3385473==    by 0x222172: Task_46_1f3cd98ac177094c9632f9c81aa71556d2feacfd911d3d139427ec94325c8 (roc_app:0)
==3385473==    by 0x1C0D04: Task_53_b7f067e6f5939fbe06dd68ed4b36fad898cbfd8ef8d993964d5cd10b12ac3ec (roc_app:0)
==3385473==    by 0x1ECAD1: Task_96_38ac12d038fd8df52070eb8edb3aab96b2fa7b50fc7a9367255428634fa0264e (roc_app:0)
==3385473==    by 0x218289: Task_46_5e6d2773e4caec97557de41edef7addcc8c8bc472f779d224a7d61166dbaabe (roc_app:0)
==3385473==    by 0x1E7D02: _158_3fe74881edf546beefa6734056b1899c37505b1c34fcce49bbd7b44b157595 (roc_app:0)
==3385473==  Block was alloc'd at
==3385473==    at 0x48447A8: malloc (vg_replace_malloc.c:446)
==3385473==    by 0x2B074D: <roc_std::roc_str::RocStr as core::convert::From<&str>>::from (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x29A5CA: tokio::runtime::task::raw::poll (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E762D: std::sys_common::backtrace::__rust_begin_short_backtrace (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E736E: core::ops::function::FnOnce::call_once{{vtable.shim}} (in /home/gree/workspace/roc-htmx-playground/src/main)
==3385473==    by 0x2E3ADA: call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> (boxed.rs:2022)
==3385473==    by 0x2E3ADA: call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> (boxed.rs:2022)
==3385473==    by 0x2E3ADA: std::sys::pal::unix::thread::Thread::new::thread_start (thread.rs:108)
==3385473==    by 0x494439C: start_thread (pthread_create.c:447)
==3385473==    by 0x49C92A3: clone (clone.S:100)
==3385473==

The related Zulip discussion with hypotheses what the problem could be is here: https://roc.zulipchat.com/#narrow/channel/231634-beginners/topic/client-side.20web.20in.20Roc/near/484698508

@Anton-4
Copy link
Collaborator

Anton-4 commented Dec 3, 2024

In case it may help anyone, we've have had a malloc(): unaligned tcache chunk detected before with the static site gen platform roc-lang/roc#5430

@Anton-4
Copy link
Collaborator

Anton-4 commented Dec 3, 2024

Some comments from Brendan:

Yeah, this suggests that we are allocating something with the wrong size. Allocate something with no size, attempt to read a refcount from it (invalid read cause didn't allocate space for a recount), attempt to write refcount to it (invalid write).

My first guess is allocating a Box {} is not adding on the refcount.

In roc-lang/roc#5430 we also had a problem with box

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