Skip to content

A memory allocation race in lx is causing nondeterministic crashes #351

Open

Description

@silentbicycle

Running the following command:

$ while true; do sleep 0.1; ./build/bin/lx -l test < src/lx/lexer.lx && echo ok; done

will produce a steady stream of memory-related errors in lx.

There appears to be a race on malloc/realloc on a shared pointer. I am going to post a PR in a moment that disables multithreading, this issue exists as a reminder to fix it later. It's currently a distraction from other more important work.

Activity

  1. added a commit that references this issue on Apr 28, 2021
  2. katef commented on Jan 4, 2024

    @katef
    Owner

    Hm I can't reproduce this, I tried with and without asan, ubsan and efence. Any ideas?

  3. silentbicycle commented on Jan 4, 2024

    @silentbicycle
    CollaboratorAuthor

    You need to set the concurrency flag (-C) to use multiple threads. I just checked again on main and

    $ while true; do sleep 0.1; ./build/bin/lx -C8 -l test < src/lx/lexer.lx && echo ok; done
    

    still produces errors

    ok
    malloc_consolidate(): invalid chunk size
    Aborted (core dumped)
    ok
    ...
    ok
    double free or corruption (out)
    Aborted (core dumped)
    ok
    corrupted size vs. prev_size
    Aborted (core dumped)
    ok
    ...
    ok
    corrupted size vs. prev_size
    Aborted (core dumped)
    ok
    ...
    ok
    malloc(): unsorted double linked list corrupted
    Aborted (core dumped)
    ok
    double free or corruption (out)
    Aborted (core dumped)
    ok
    

    It may depend somewhat on CPU load -- if I ran multiple processes of a busywait program to bog the CPU down the failures reduced in frequency, and they returned when I stopped the busywaiters.

    It used to fail without the -C flag, because before ae73900 the default was 4 threads rather than 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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