pg-extend-rs
pg-extend-rs copied to clipboard
`panic!`ing twice crashes PG with "Illegal instruction"
OS
Ubuntu 18.04 (Windows Subsystem for Linux)
Code
panicking example package
Issue
Rust panic!() is caught and handled properly on the first call, but if called again, the server crashes:

Here's PG logs:

That little extra weird stuff
This also happens when using error!() macro, but it requires 3 executions:

Here;s PG logs:

Error, fatal and panic all cause PG to abort the transaction, where panic will cause a full restart. The illegal obstruction is concerning though.
Is this a double panic? Or is it a panic, and then a different transaction also panicking?
Unless psql is not setting AUTOCOMMIT then yes, they are separate transactions panicking
This is happening on Windows? I wonder if this behavior can be reproduced on a vanilla Linux box.
Same error happens in a Docker container running PG10

I haven’t looked into this, yet, but what is the expected behavior of Postgres when it panics? It might do exactly this. It would be interesting if we had a test case that showed this with and without pg-extend. That would require a vanilla C extension I think.
Looking at PG source code, I found this:

The important part is:
If elevel >= ERROR, the call will not return; we try to inform the compiler of that via pg_unreachable()
So, if the log level is ERROR or higher, there will be a different behaviour (no return). Perhaps this might explain the weird behaviour?
Yes. That’s what I was trying to explain. Error and higher log statements have the side effect of killing the transaction/process/server, depending on which you use.
It’s really ugly imo, but that’s the way it works.