Skip to content

Unit tests on Windows with DEBUG_LOCKORDER have been broken for a while #36973

Backlog

Description

@darosior

I was testing some socket stuff in a Windows VM and noticed unit tests don't pass for a mingw build with -DCMAKE_BUILD_TYPE=Debug. The regression was introduced in #35614. To reproduce, build with DEBUG_LOCKORDER and run that HTTP server test:

test_bitcoin --run_test=httpserver_tests/http_socket_error_tests

Haven't looked into the bug myself, but apparently it's trivial to fix. See slop below.

LLM summary of the issue

In several socket paths, WSAGetLastError() is read after leaving the LOCK(m_sock_mutex) scope that wrapped the send()/recv() call. With DEBUG_LOCKORDER, releasing the lock runs pop_lock() (src/sync.cpp:212, :215), which calls std::this_thread::get_id(). With the mingw-w64 posix thread model, that call resets the Windows last error to 0. A WSAEWOULDBLOCK is then read as error 0, which IOErrorIsPermanent() treats as permanent, so the connection is dropped.

Suggested fix. Read WSAGetLastError() inside the lock scope, right after the socket call. With that change, the test passes on Windows Debug.

Activity

  1. added this to the 33.0 milestone on Nov 25, 2026
  2. fanquake commented on Nov 25, 2026

    @fanquake
    Member

    The fix here should also be backported to 32.x.

  3. pinheadmz commented on Nov 30, 2026

    @pinheadmz
    Member

    Just double checking, your build was cross-compiled MinGW and not the (recently updated to) clang-cl on windows native?

  4. darosior commented on Nov 30, 2026

    @darosior
    MemberAuthor
  5. hebasto commented on Nov 30, 2026

    @hebasto
    Member

    Just double checking, your build was cross-compiled MinGW and not the (recently updated to) clang-cl on windows native?

    Unit tests on Windows with DEBUG_LOCKORDER have been reproduced here: hebasto/bitcoin-core-nightly#497.

  6. pinheadmz commented on Nov 30, 2026

    @pinheadmz
    Member

    Confirmed the unit test failure locally and only with a cross-compiled debug build, so I have a baseline to review #37005

    Sloppy explanation: clang-cl implements get_id() without touching the thread, but the posix model makes an extra call that succeeds, wiping the error value.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions