Open tysonzero opened 1 month ago
Sadly using hasql-pool
and/or hasql-transaction
does not circumvent this issue. However using the raw sql
function to do the insert does.
Narrowed it down quite a bit further. A simple seq stmt (pure ())
segfaults also, but if you remove the insert
and switch the type accordingly then seq stmt (pure ())
does not segfault, so insert
is where the segfault lives.
Inserting with opaleye
does not segfault, so it seems to be specific to something rel8
is doing.
Can also reproduce in stack repl
, by simply pretty-printing putStrLn . showInsert
— without ever trying to execute the query.
@tysonzero I don't think it's anything concerning in the rel8 library or dependencies. I think it's a bug in GHCi. As you noticed: when compiled, the code works fine; the segfaults only happens at the REPL.
As a workaround, you may have luck with loading your modules after :set -fobject-code
. Per my testing, this stops the crashes. It switches GHCi from "interpreter mode" to loading compiled modules... the GHC User Guide has more to say.
Another way to work around is to :load the entire rel8 package source intepreted into ghci (e.g. git clone rel8 && cabal repl) — then crashing stops too.
The segfaults occur when you mix compiled + interpreted code:
and both workarounds avoid executing this mix. Either all compiled, or all interpreted.
@ulidtko thank you for investigating! Could you make an issue on the GHC bug tracker? Also is this reproducible with a newer GHC?
If you don't have the time right now, I can make an issue.
Hi @TeofilC!
Trying to retest on GHC HEAD today, but repro involves installing rel8
as a compiled package — so, far from minimal...
Please go ahead with filing an issue; I only found #22956 for 9.6 but it's unclear if underlying cause is the same.
To save folks reading the GHC issue. This is a known bug in GHC and there is a fix, which should be extensively backported. So hopefully this should be fixed in the next minor release of maintained major versions of GHC
Fix has landed to GHC master & I retested it, works indeed:
GHCi, version 9.11.20240628: https://www.haskell.org/ghc/ :? for help
[1 of 2] Compiling Main ( crasher-rel8#325.hs, interpreted )
Ok, one module loaded.
ghci> :main
INSERT INTO "test" ("colA",
"colB")
SELECT
CAST(CAST(NULL AS "bpchar"(1)[]) AS "bpchar"(1)[]) as "_1",
CAST(CAST(NULL AS "bpchar"(1)[]) AS "bpchar"(1)[]) as "_2"
FROM (SELECT
*
FROM (SELECT
0) AS "T1"
WHERE (CAST(FALSE AS boolean))) AS "T1"
ON CONFLICT DO NOTHING
But if I understand correctly, backporting it to 9.6, 9.8, 9.10 remains to be done.
They work fine when compiled, and select statements work correctly when compiled and also in the repl.
Environment information:
Setup:
Putting
rows = values @_ @[] undefined
still segfaults, butrows = undefined
will run into anundefined
error instead before hitting any segfault.