os_win.c: fix #221 WAL STATUS_IN_PAGE_ERROR crash on Windows without SEH - #7
os_win.c: fix #221 WAL STATUS_IN_PAGE_ERROR crash on Windows without SEH#7hazyhaar wants to merge 1 commit into
Conversation
6568fac to
4b2d8a8
Compare
|
Thanks for taking on #221 — the crash is real and I want it fixed. I read the PR in detail, but I cannot merge it in this form, for two kinds of reasons. Process and reproducibility
DesignReplacing the shared
A two-process writer + checkpointer loop cannot observe 1–3; they need a long-lived reader concurrent with a writer, and processes racing the flush. What I would like to do insteadEmulate what SEH gives MSVC builds rather than avoiding the mapping. Go already has the primitive:
I have verified the mechanism on Linux (a fault inside a truncated Edited: the extended error code above was first written as 6410; the correct value of SQLITE_IOERR_IN_PAGE is 8714 (SQLITE_IOERR | 34<<8). |
4b2d8a8 to
5f3b6fb
Compare
Add lib/libsqlite3_windows.go for platform support, update CHANGELOG.md, and add issue221_windows_test.go (skipping until upstream builders run 'make vendor' against the patched libsqlite3). Full SEH patch, generator configuration, and automated tests are submitted upstream to cznic/libsqlite3.
5f3b6fb to
b6ebbf8
Compare
|
Thanks for the thorough review and architectural guidance. We have fully refactored this PR according to your requirements:
Once |
Problem Description
Under
-DSQLITE_OMIT_SEH,winShmMapmaps shared memory usingMapViewOfFilewithout structured exception handling (__try / __except). When a memory page fault cannot be satisfied (e.g. concurrent WAL file truncation, network disk latency, or antivirus/EDR file scanning), Windows raises the hardware exceptionSTATUS_IN_PAGE_ERROR(0xc0000006). In pure-Go environments without CGO, this unhandled exception immediately crashes the entire Go process.Root Cause & Solution
-DSQLITE_OMIT_SEH:winShmMapallocates shared memory regions on the process heap viasqlite3MallocZeroand synchronizes with the backing-shmfile via synchronousReadFile/WriteFilecalls.ofst == 1) strictly flushes onlynBackfill(offset 96) andnBackfillAttempted(offset 128) on 4 bytes each, preventing any overwriting of concurrent writermxFrame.ofst >= 3) strictly flushes only the specific 4-byte read mark (100 + 4*(ofst-3)).ofst == 0) and crash recovery (ofst == 2).(!ok && nDone==0)with(!ok || nDone!=nWant)to reject partial reads.winRetryIoerrretry loops.Verification
mxFramedisk-witness sampling, proving zero corruption and passingPRAGMA integrity_check.make build_all_targetsandundupdeduplication.