win_flex.exe (and likely win_bison.exe) isn't concurrency safe - Mailing list pgsql-hackers

From Andres Freund
Subject win_flex.exe (and likely win_bison.exe) isn't concurrency safe
Date
Msg-id 20220902224335.lxlkpn2vuw7v2j7d@awork3.anarazel.de
Whole thread Raw
Responses Re: win_flex.exe (and likely win_bison.exe) isn't concurrency safe
Re: win_flex.exe (and likely win_bison.exe) isn't concurrency safe
List pgsql-hackers
Hi,

building PG with meson on windows I occasionally got weird errors around
scanners. Sometimes scanner generation would fail with

  win_flex.exe: error deleting file C:\Users\myadmin\AppData\Local\Temp\~flex_out_main_2

sometimes the generated scanner would just be corrupted.


I was confused by only hitting this in local VM, not in CI, but after finally
hunting it down it made more sense:
https://github.com/lexxmark/winflexbison/issues/86

https://github.com/lexxmark/winflexbison/blob/master/flex/src/main.c#L1051

It uses a temporary file name without any concurrency protection. Looks like
windows' _tempnam is pretty darn awful and returns a predictable name as long
as no conflicting file exists.

Our documentation doesn't point to winflexbison, but recommends using
flex/bison from msys. But I've certainly read about others using winflexbison,
e.g. [1] [2]. The flex/bison in 'chocolatey', which I've also seen referenced,
is afaics winflexbison.


Afaict the issue also exists in our traditional windows build - but I've not
seen anybody report this as an issue.


I started this thread to document the issue, in case developers using visual
studio are hitting this today.


It looks like a similar issue exists for the windows bison port:
https://github.com/lexxmark/winflexbison/blob/b2a94ad5fd82cf4a54690a879e14ff9511b77273/bison/src/output.c#L816

I've not observed that failure, presumably because the window for it is much
shorter.


For the meson build it is trivial to "address" this by setting FLEX_TMP_DIR to
a private directory (which we already need to deal with lex.backup), something
similar could be done for src/tools/msvc.


Unless we think it'd be better to just refuse to work with winflexbison?


Greetings,

Andres Freund

[1] https://www.postgresql.org/message-id/ae44b04a-2087-fa9d-c6b1-b1dcbbacf4ae%40dunslane.net
[2] https://www.postgresql.org/message-id/CAGRY4nxJNqEjr1NtdB8%3DdcOwwsWTqQfykyvgp1i_udCtw--BkQ%40mail.gmail.com



pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: introduce bufmgr hooks
Next
From: Nathan Bossart
Date:
Subject: Re: Backpatching nbtree VACUUM (page deletion) hardening