8000 bindings: the curl worker thread reads the logger while a session frees it · Issue #95 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

bindings: the curl worker thread reads the logger while a session frees it #95

Closed

Description

@Lillecarl

What

ThreadSanitizer reports a data race between a free inside _ext and a read
by Nix's own curl file-transfer worker thread, in nix::Activity::~Activity.

The soak had already finished at that point:

SOAK    10.929 lane=3 END   tests/nanopynix/inproc/test_inproc.py::test_inproc_eval_value_navigation ok
SOAK END ok=68 fail=0
==================
WARNING: ThreadSanitizer: data race (pid=2)

So this is a teardown defect, and not something the schedule drives.

Write of size 8 at 0x72040001b7d0 by thread T7 'nix-store_3':
  #0 operator delete(void*, unsigned long)
  nixidae/nixidae#30..#5 (_ext.cpython-314-x86_64-linux-gnu.so)
  nixidae/nixidae#35 _PyEval_EvalFrameDefault

Previous read of size 8 at 0x72040001b7d0 by thread T27:
  #0 nix::Activity::~Activity() ../logging.cc:480
  nixidae/nixidae#32 std::unique_ptr<nix::Activity>::~unique_ptr()
  nixidae/nixidae#33 nix::curlFileTransfer::TransferItem::~TransferItem() ../filetransfer.cc:216
  ...
  nixidae/nixidae#51 nix::curlFileTransfer::workerThreadMain() ../filetransfer.cc:911
  nixidae/nixidae#52 nix::curlFileTransfer::workerThreadEntry() ../filetransfer.cc:998

Why it is real

Activity::~Activity calls logger.stopActivity(id). It holds a Logger &,
so it reads the logger object at destruction.

_ext frees on a Store thread while that read is in flight. This is a read of
memory that another thread is freeing, which is a use-after-free and not only
an ordering question.

Thread T27 is Nix's own thread. curlFileTransfer starts it in its
constructor (filetransfer.cc:842), which getDefaultSubstituters() reaches
through HttpBinaryCacheStoreConfig::openStore. Nothing in this repository
starts it, joins it, or knows when it stops.

Why nanopynix meets it

install_logger puts a PyLogger in nix::logger, and remove_logger
takes it out again when a session closes. The curl worker thread outlives the
session's own threads, so it can still be destroying a TransferItem, and
with it an Activity, after the session decides the logger is finished with.

Upstream Nix does not meet this, because the process ends rather than swapping
its logger out.

How it was found

The concurrency soak, on ci-develop, run 30913072524, seed 1, TSAN. The
schedule that preceded it is in the artifact
soak-nix_2_34-run1-inproc.json.

What to check

  1. Whether remove_logger is the free. The stack shows _ext and nothing
    more, because the extension is built without frame pointers in that path.
    A build with symbols would name it.
  2. Whether a Store that reaches a substituter is required to reproduce it.
    getDefaultSubstituters is what starts the curl thread, so a soak with no
    substituter configured may never see this.
  3. What a correct teardown looks like. Nix gives no way to join the curl
    worker, so leaving the logger installed for the life of the process is one
    answer, and it costs a PyLogger that never goes away.

Acceptance criteria

  • The TSAN soak reports no race in nix::Activity::~Activity over its five
    seeds.
  • The reason the chosen teardown is correct is written where the next reader
    of install_logger and remove_logger will find it.
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

    source: nanopynix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0