Use dynamic multithreaded runtime library on windows #127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes duckdb/duckdb_spatial#405
This was quite a journey to debug, and a lot of this windows stuff is new to me, but my understanding of the issue and the fix is that gyp on windows by default compiles node add-ons with a "static runtime library". This means that the native node add-on will not share the heap with any other dynamically loaded libraries (such as DuckDB extensions). When creating an R-Tree in the spatial extension, we hijack the query plan and instantiate a
PhysicalCreateRTreeIndex
operator, which is a subclass of thePhysicalOperator
class present in DuckDB core. This thus gets allocated within the spatial extensions heap, but passed on and ultimately free'd within the DuckDB add-ons heap, causing a crash (?). My understanding is that the fact that we subclass across library boundaries is the key to why this crashes. A similar issue seems to be common when using the static runtime and templates defined in other libraries1.Note for the future: on debug builds these flags need to change to
RuntimeLibrary: 3
and/MDd
to link the debug dynamic library instead. e.g.But we don't seem to support separate debug and release targets in this add-on anyway sooo ¯\(ツ)/¯
Some other related threads:
Footnotes
https://stackoverflow.com/questions/35310117/debug-assertion-failed-expression-acrt-first-block-header ↩