-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Malloc double free error when disconnecting in finalizer #35
Comments
Hm. Thanks for reporting this. By the way, the HDBC-odbc drivers are a lot more stable and performant than the HDBC-postgresql ones (even on postgresql databases): it's received a lot more attention and will soon have a GSOC student working on it. Is there a reason you're still using HDBC-postgresql? |
We're using the error types defined in HDBC-postgresql in a few places, not sure if there are any alternatives for that. If you need any help trying to debug this, just let me know. I've tried to come up with a small, reproducible test case, but I can't: it seems to be some weird interplay between resource-pool, HDBC-postgresql and, for some reason, aws. |
In all honesty I won't be able to take a close look at this for quite some time. Any help would be greatly appreciated. |
Hmm, I could try to get a good test case again (though I'm not hopeful), but I'm not really up for debugging refcounting C code... |
@zenzike are you referring to the |
Yes, I was talking about the |
Just wanted to say that there is a 2.5 branch with HDBC-odbc internals changed quite a bit. It doesn't use refcounting anymore (because that wasn't safe in multithreaded environments and programs crashed), instead it relies on GHC finalizers to do cleanups. The problem with 2.5 branch is that it offers deterministic resources cleanup, which requires patched version of HDBC with this pull request: hdbc/hdbc#32 If that pull request would ever be accepted, I am ready to release new HDBC-odbc version. We are using it in production for a long time already (with MSSQL driver) and it seems to be very stable. |
@zenzike can we quantify how much faster? Setting up odbc isn't that fun either, at least on OSX, compared to using Have we thought about rewriting this package using The IConnection typeclass seems kind of rigid, but we could probably integrate it somehow. |
It seems like a lot of what I'm looking for has been done in the |
I spent way too long debugging this before finding this issue and bos/pool#18. Luckily I was able to reproduce this behavior. Here's a tiny program that reliably crashes: -- base-4.13.0.0, HDBC-2.4.0.3, HDBC-postgresql-2.3.2.7, resource-pool-0.2.3.2
module Main ( main ) where
import qualified Data.Pool as Pool
import qualified Database.HDBC as Sql
import qualified Database.HDBC.PostgreSQL as Postgres
main :: IO ()
main = do
putStr $ unlines
[ "This program will attempt to crash."
, "It will print out attempt numbers as it goes."
, "Press Ctrl-C to exit."
]
attempt 1
attempt :: Int -> IO ()
attempt n = if n > 32 then fail "Failed to crash!" else do
print n
pool <- Pool.createPool (Postgres.connectPostgreSQL "") Sql.disconnect 1 1 1
Pool.withResource pool . const $ pure ()
attempt $ n + 1 I'm not familiar with the internals of
I don't have any insight into how to fix the root problem here, but hopefully that helps. Maybe someone who knows more about this stuff can use my minimal example here to fix things. Happy hacking! Edited to add: When running these tests, the PostgreSQL outputs logs like this:
|
@tfausak not sure the state of this issue, but I attempted to retry failure and could not reproduce with
|
Huh, I can't seem to reproduce the error anymore either. No clue what changed 😕 |
@tfausak GHC 8.8.4 came out with "self-healing mode" it seems. |
@tfausak the issues resurfaces when you compile with |
@tfausak I can confirm now that it crashes give your example with
|
We're seeing a crash using HDBC-postgresql together with resource-pool 0.2.2.0. I originally filed this as bos/pool#18 but there it seemed the problem was in HDBC-postgresql and its handling of disconnect in finalizers. See that ticket for details, but in short it seems that if external code calls
disconnect
from a finalizer, HDBC-postgresql will try to disconnect again from its own finalizer.The text was updated successfully, but these errors were encountered: