Skip to content

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

@gree7

Description

@gree7

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions