Re: "could not reattach to shared memory" on buildfarm member dory
Tom Lane <tgl@sss.pgh.pa.us>
[ Thanks to Stephen for cranking up a continuous build loop on dory ] Noah Misch <noah@leadboat.com> writes: > On Tue, Apr 24, 2018 at 11:37:33AM +1200, Thomas Munro wrote: >> Maybe try asking what's mapped there with VirtualQueryEx() on failure? > +1. An implementation of that: > https://www.postgresql.org/message-id/20170403065106.GA2624300%40tornado.leadboat.com So I tried putting in that code, and it turns the problem from something that maybe happens in every third buildfarm run or so, to something that happens at least a dozen times in a single "make check" step. This seems to mean that either EnumProcessModules or GetModuleFileNameEx is itself allocating memory, and sometimes that allocation comes out of the space VirtualFree just freed :-(. So we can't use those functions. We have however proven that no new module gets loaded during VirtualFree or MapViewOfFileEx, so there doesn't seem to be anything more to be learned from them anyway. What it looks like to me is that MapViewOfFileEx allocates some memory and sometimes that comes out of the wrong place. This is, um, unfortunate. It also appears that VirtualFree might sometimes allocate some memory, and that'd be even more unfortunate, but it's hard to be certain; the blame might well fail on VirtualQuery instead. (Ain't Heisenbugs fun?) The solution I was thinking about last night was to have PGSharedMemoryReAttach call MapViewOfFileEx to map the shared memory segment at an unspecified address, then unmap it, then call VirtualFree, and finally call MapViewOfFileEx with the real target address. The idea here is to get these various DLLs to set up any memory allocation pools they're going to set up before we risk doing VirtualFree. I am not, at this point, convinced this will fix it :-( ... but I'm not sure what else to try. In any case, it's still pretty unclear why dory is showing this problem and other buildfarm members are not. whelk for instance seems to be loading all the same DLLs and more besides. regards, tom lane
Commits
-
Avoid "could not reattach" by providing space for concurrent allocation.
- 203886d3ae22 9.4.22 landed
- f5989b379cef 10.8 landed
- 7a5677818556 9.5.17 landed
- 57ebbbb8f15a 9.6.13 landed
- e45a8ff87149 11.3 landed
- 617dc6d299c9 12.0 landed
-
Assert that pgwin32_signal_initialize() has been called early enough.
- ab9ed9be2378 12.0 landed
-
Remove investigative code for can't-reattach-to-shared-memory errors.
- bcbf2346d69f 11.0 landed
-
Does it help to wait before reattaching?
- 23078689a992 11.0 landed
-
Map and unmap the shared memory block before risking VirtualFree.
- 73042b8d136f 11.0 landed
-
Further effort at preventing memory map dump from affecting the results.
- ce07aff48f15 11.0 landed
-
Remove Windows module-list-dumping code.
- f7df8043f08a 11.0 landed
-
Dump full memory maps around failing Windows reattach code.
- 6ba0cc4bd3a6 11.0 landed
-
Get still more info about Windows can't-reattach-to-shared-memory errors.
- eb16011f4c08 11.0 landed
-
Get more info about Windows can't-reattach-to-shared-memory errors.
- 68e7e973d222 11.0 landed
-
Try to get some info about Windows can't-reattach-to-shared-memory errors.
- 63ca350ef9f5 11.0 landed