Skip to content
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

Should finish be uninterruptible? #17

Open
codygman opened this issue Mar 11, 2021 · 2 comments
Open

Should finish be uninterruptible? #17

codygman opened this issue Mar 11, 2021 · 2 comments

Comments

@codygman
Copy link

codygman commented Mar 11, 2021

This change seems to fix the symptom I get a couple levels up the abstraction chain in Persistent:

finish :: Connection
       -> IO ()
finish (Conn fp _) = do
    uninterruptibleMask_ $ finalizeForeignPtr fp

yesodweb/persistent#1199

I discovered this fixed that symptom here: yesodweb/persistent#1199 (comment)

@codygman
Copy link
Author

codygman commented Mar 11, 2021

I also see that odbc uses withAsyncBound here and says:

-- | Run an action in a bound thread. This is neccessary due to the
-- interaction with signals in ODBC and GHC's runtime.

I'm not sure if this applies to postgresql-libpq.

Edit: Here is what the async docs have to say about forkOS, which is what makes withAsyncBound different:

However, forkOS creates a bound thread, which is necessary if you need to call foreign (non-Haskell) libraries that make use of thread-local state, such as OpenGL (see Control.Concurrent).

So I guess the question is:

Does Connection, I guess the fp here, make use of thread-local state?

@codygman
Copy link
Author

codygman commented Mar 11, 2021

Still not sure about this, but this also fixes the symptom I linked to in my initial description:

finish :: Connection
       -> IO ()
finish (Conn fp _) = do
    -- uninterruptibleMask_ $ finalizeForeignPtr fp
    runInBoundThread $ finalizeForeignPtr fp

I'm assuming this is safer since the exceptions won't be both masked and uninterruptible in the Bound thread but I'm honestly kinda new to low-level Haskell and the FFI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant