-
Couldn't load subscription status.
- Fork 2.7k
Disable constexpr std::mutex on Windows #17991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
It appeared that wget is not present by default on Windows runners, will add explicit install now. |
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
On Windows the `constexpr` constructor of `std::mutex`, that was supposed to be there since C++11, was not implemented until VS2022. Its implementation has required to use Slim Reader/Writer (SRW) Locks ([ref](https://learn.microsoft.com/en-us/windows/win32/sync/slim-reader-writer--srw--locks)) that are only supported since Window 7, but VS2019 was still supporting Windows Vista as a target ([more details from SO](https://stackoverflow.com/a/74255773)). The implementation of `constexpr std::mutex` in MSVC has required the ABI breakage in C++ STL that was eventually added in VS2022 17.10 ([commit](microsoft/STL@4aad4b8)). This commit has introduced the macro `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` that can be defined to stay ABI compatible with older versions of C++ stdlib. Thus the binaries built with VS2022 17.10 or later and without this macro cannot be run with older versions of C++ stdlib `msvcp140.dll` even if they do not use `constexpr std::mutex` - any mutex usage will crash with something like this ([more examples and comments from MSFT](https://web.archive.org/web/20250618223106/https://developercommunity.visualstudio.com/t/Access-violation-in-_Thrd_yield-after-up/10664660)): ``` Faulting application name: duckdb.exe, version: 1.3.1.0, time stamp: 0x684fdb82 Faulting module name: MSVCP140.dll, version: 14.36.32532.0, time stamp: 0x04a30cf0 Exception code: 0xc0000005 ``` This PR adds the `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` macro definition to Windows builds assuming that we are not going to use `constexpr` constructor of `std::mutex` and we want to be able to run with `msvcp140.dll` while being compiled with newer toolchains. Note, that running binaries, that were built against `msvcp140.dll` version `14.40+`, in environment with earlier versions `msvcp140.dll` is not officially supported by MSFT ([ref](https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017?view=msvc-170)). But we don't really have a choice here (unless we want to keep DuckDB itself on VS2019). Extensions (which build should include the engine CMake file being update by this PR) are going to be loaded though JDBC into JVM processes. As of mid 2025, OpenJDK builds from some of major vendors (e.g. Amazon Corretto), including the latest stable JDK 24 (released in March 2025) are still using VS2019 (likely the topic of this issue is one of the reasons for that). And all these JDKs include a vendored copy of `msvcp140.dll` version `14.29`. Due to the way, how Windows shared lib loader works, this vendored C++ stdlib will be loaded by the JVM instead of any system one. And then later when the JVM will load DuckDB extensions shared libs through JDBC - these extensions will also use this pre-loaded version of C++ stdlib, as we do not do static linking for it. In general, LTS JDK versions have 10+ years of production support (for example, JDK 6 released in late 2006 is still supported by some vendors). And even if later updates of LTS JDKs (11, 17, 21, 24 etc) will move to a newer version of MSVC toolchain - the old JDK binaries are going to be still in use for a long time. Thus this change is proposed as a permanent change - not a temporary workaround. Testing: additional test run of `unittest.exe` is added that uses `msvcp140.dll` from VS2019 instead of the system-provided one. Fixes: duckdb#17971
716df50 to
a92491b
Compare
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
|
Windows CI run has passed I've filed #17993 as an attempt to fix the |
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
|
Thanks! |
Use correct expression function after filter pushdown (duckdb/duckdb#17860) Disable constexpr std::mutex on Windows (duckdb/duckdb#17991)
Use correct expression function after filter pushdown (duckdb/duckdb#17860) Disable constexpr std::mutex on Windows (duckdb/duckdb#17991) Co-authored-by: krlmlr <[email protected]>
This is a backport of the PR duckdb#169 to `v1.3-ossivalis` stable branch. This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
This is a backport of the PR #169 to `v1.3-ossivalis` stable branch. This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` flag for Windows builds that prevents crashes when the host process, into which the ODBC driver is loaded, is run using older versions of C++ stdlib. Details: duckdb/duckdb#17991 Testing: additional test run added that uses `msvcp140.dll` from VS2019 instead of the system-provided one.
Note: this PR is a draft, please do not merge. This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch.
Note: this PR is a draft, please do not merge. This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch.
This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch. Testing: it was checked in manual CI runs, that added unit test run actually causes a crash when `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` is not used.
This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch. Testing: it was checked in manual CI runs, that added unit test run actually causes a crash when `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` is not used.
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` preprocessor definition to Python wheel builds on Windows. For details see duckdb#17991, where the same definition was added for CLI builds. Fixes: duckdb#17971
This change adds `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` preprocessor definition to Python wheel builds on Windows. For details see duckdb#17991, where the same definition was added for CLI builds. Fixes: duckdb#17971
This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch. Testing: it was checked in manual CI runs, that added unit test run actually causes a crash when `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` is not used.
This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch. Testing: it was checked in manual CI runs, that added unit test run actually causes a crash when `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` is not used.
This change enbales additional run of the test suite for all extensions using C++ stdlib DLL from Visual Studion 2019. This is done to check the compatibility with older versions of C++ stdlib introduced in duckdb#17991 New workflow step is only run for `x64-windows-static-md` build arch. Testing: it was checked in manual CI runs, that added unit test run actually causes a crash when `_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR` is not used.
This change makes all CMake targets to use `-MT`/`-MTd` compilation flags for Windows MSVC builds. This way the MSVC runtime library is linked statically and the workaround for VS2019 added in duckdb#17991 is no longer necessary. `extension-ci-tools` PR: duckdb/extension-ci-tools#276 Testing: checked locally that `duckdb-httpfs` can successfully fetch HTTP(S) resources with this and `extension-ci-tools` changes applied. Ref: duckdblabs/duckdb-internal#2036
This change makes all CMake targets to use `-MT`/`-MTd` compilation flags for Windows MSVC builds. This way the MSVC runtime library is linked statically and the workaround for VS2019 added in duckdb/duckdb#17991 is no longer necessary. `extension-ci-tools` PR: duckdb/extension-ci-tools#276 Ref: duckdblabs/duckdb-internal#2036
This change makes all CMake targets to use `-MT`/`-MTd` compilation flags for Windows MSVC builds. This way the MSVC runtime library is linked statically and the workaround for VS2019 described in duckdb/duckdb#17991 is no longer necessary. `extension-ci-tools` PR: duckdb/extension-ci-tools#276 Ref: duckdblabs/duckdb-internal#2036
This change makes all CMake targets to use `-MT`/`-MTd` compilation flags for Windows MSVC builds. This way the MSVC runtime library is linked statically and the workaround for VS2019 added in duckdb/duckdb#17991 is no longer necessary. `extension-ci-tools` PR: duckdb/extension-ci-tools#276 Ref: duckdblabs/duckdb-internal#2036
This change makes all CMake targets to use `-MT`/`-MTd` compilation flags for Windows MSVC builds. This way the MSVC runtime library is linked statically and the workaround for VS2019 described in duckdb/duckdb#17991 is no longer necessary. `extension-ci-tools` PR: duckdb/extension-ci-tools#276 Ref: duckdblabs/duckdb-internal#2036
On Windows the
constexprconstructor ofstd::mutex, that was supposed to be there since C++11, was not implemented until VS2022. Its implementation has required to use Slim Reader/Writer (SRW) Locks (ref) that are only supported since Window 7, but VS2019 was still supporting Windows Vista as a target (more details from SO).The implementation of
constexpr std::mutexin MSVC has required the ABI breakage in C++ STL that was eventually added in VS2022 17.10 (commit). This commit has introduced the macro_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTORthat can be defined to stay ABI compatible with older versions of C++ stdlib. Thus the binaries built with VS2022 17.10 or later and without this macro cannot be run with older versions of C++ stdlibmsvcp140.dlleven if they do not useconstexpr std::mutex- any mutex usage will crash with something like this (more examples and comments from MSFT):This PR adds the
_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTORmacro definition to Windows builds assuming that we are not going to useconstexprconstructor ofstd::mutexand we want to be able to run withmsvcp140.dllwhile being compiled with newer toolchains.Note, that running binaries, that were built against
msvcp140.dllversion14.40+, in environment with earlier versionsmsvcp140.dllis not officially supported by MSFT (ref). But we don't really have a choice here (unless we want to keep DuckDB itself on VS2019). Extensions (which build should include the engine CMake file being update by this PR) are going to be loaded though JDBC into JVM processes. As of mid 2025, OpenJDK builds from some of major vendors (e.g. Amazon Corretto), including the latest stable JDK 24 (released in March 2025) are still using VS2019 (likely the topic of this issue is one of the reasons for that). And all these JDKs include a vendored copy ofmsvcp140.dllversion14.29. Due to the way, how Windows shared lib loader works, this vendored C++ stdlib will be loaded by the JVM instead of any system one. And then later when the JVM will load DuckDB extensions shared libs through JDBC - these extensions will also use this pre-loaded version of C++ stdlib, as we do not do static linking for it. In general, LTS JDK versions have 10+ years of production support (for example, JDK 6 released in late 2006 is still supported by some vendors). And even if later updates of LTS JDKs (11, 17, 21, 24 etc) will move to a newer version of MSVC toolchain - the old JDK binaries are going to be still in use for a long time.Thus this change is proposed as a permanent change - not a temporary workaround.
Testing: additional test run of
unittest.exeis added that usesmsvcp140.dllfrom VS2019 instead of the system-provided one.Fixes: #17971
Edit: added
wgetinstallation on Windows CI, removed "1.3" labels as this PR is intended to be the mainline one whenv1.3-ossivaliswill be merged into themainbranch later.