Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-42466

Windows threadpool crashes with STATUS_STACK_OVERFLOW when thread_stack is a multiple of 64 KiB

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Critical
    • Resolution: Unresolved
    • 10.11, 11.4, 11.8, 12.3
    • 10.11, 11.4, 11.8, 12.3
    • Platform Windows
    • None
    • Windows x64 (MSVC Debug, RelWithDebInfo, MinSizeRel)

    Description

      While testing PR #6213 (MDEV-42362), running main.lotofstack with --thread-stack=192K crashed mariadbd.exe on all three Windows CI builds instead of returning ER_STACK_OVERRUN_NEED_MORE:

      On AppVeyor, the server log shows STATUS_STACK_OVERFLOW (0xc00000fd) right before double-faulting during backtrace collection (exit 1280 / client errno 2013 across all three builds):

      261125 11:06:21 [ERROR] C:/projects/server/_build/sql/mariadbd.exe got exception 0xc00000fd ;
      ...
      Server version: 10.11.21-MariaDB-log source revision: bd6416c4bb8d1da6ed745e6e2e5442cf22f4c487
      ...
      Attempting backtrace. Include this in the bug report.
      (note: Retrieving this information may fail)
       
      Thread pointer: 0x20ee57d5fb8
      

      On Windows, thread_handling defaults to pool-of-threads. In TP_pool_win::init() (sql/threadpool_win.cc), StackReserve is set directly to my_thread_stack_size without any extra headroom:

      stackinfo.StackCommit = 0;
      stackinfo.StackReserve = (SIZE_T)my_thread_stack_size;
      

      Unlike POSIX, where my_setstacksize() (mysys/my_pthread.c) adds guard_size, this leaves no margin for Windows stack overhead. With the default 292K stack, the issue stays hidden because Windows rounds StackReserve up to a 64 KiB multiple (320 KiB), giving ~28 KiB of extra space. Exact 64 KiB multiples (192K, 256K, 384K, 512K) get no rounding cushion at all.

      At the same time, two things eat into that reservation:

      • my_get_stack_bounds() (mysys/my_stack.c) falls back on Windows to the stack pointer inside OS_thread_info::init(), which is already several KiB below the real top of stack due to the Windows threadpool callback frames.
      • Windows reserves ~8 to 12 KiB of guard and overflow pages at the bottom of the stack.

      When a recursive path checks against STACK_MIN_SIZE (16,000 bytes), like Json_table_nested_path::print() on 5000 nested JSON_TABLE paths, the OS stack runs out before check_stack_overrun() finishes reporting the error.

      To reproduce, start mariadbd.exe on Windows with default pool-of-threads and --thread-stack=192K, then run the MDEV-40847 EXPLAIN EXTENDED query from mysql-test/main/lotofstack.test.

      Attachments

        Issue Links

          Activity

            People

              gkodinov Georgi Kodinov
              aquila Aquila Macedo
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.