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

Fix segfault for ghc 9.2 #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix segfault for ghc 9.2 #48

wants to merge 1 commit into from

Conversation

ondrap
Copy link

@ondrap ondrap commented Mar 9, 2023

I tried to upgrade my compiler to ghc 9.2.5 and the who thing just stopped working. Ultimately, I found that the freeDbcIfNotAlready is being started practically at the first GC cycle. It seems the compiler was able to optimize the structure out by inlining the functions so that in the end there was nothing pointing to the DbcWrapper.

Marking one of the function that use the wrapperNOINLINE seems to help; though, it seems to me some other solution might be well preferable (in the end, using some kind of with function usually works better).

@ak-coram
Copy link

@ondrap This issue seems to be even more prevalent on newer GHC versions (e.g. 9.4.5) and statements seem to be affected as well. Additionally the NOINLINE workaround doesn't seem to work anymore.

@flhorizon
Copy link

Hello, I had a similar issue when upgrading from GHC 8.6 to 9.4.8.

I believed I've finally fixed the issue (had "Tried to use a disposed ODBC Statement" and sometimes the same about the connection handle) and finally had a break-through.

I've taken inspiration from this post recommending to attach the finalize to an embedded IORef:

https://discourse.haskell.org/t/using-the-garbage-collector-to-free-user-resources/5532/5

And reproduced the reaperRef pattern from:

https://hackage.haskell.org/package/resource-pool-0.4.0.0/docs/src/Data.Pool.Internal.html#newPool

It's only using the reaperRef pattern that I had a definite improvement.
My previous tries were:

  • compiling with -fno-cse
  • adding StrictData extension
  • no-inline 'ing all IO functions in .hsc files
  • and settings __attribute__((noline)) in the cbits functions
  • masking async exceptions on alloc/free foreign calls and modifyMVar expressions

Though the stability improvement from my changes may be due to a mix of all this, I have yet to test whether any change besides the reaper ref ones are actually crucial

@ak-coram
Copy link

@flhorizon: I've replaced all calls to addFinalizer with mkWeakMVar on the relevant MVars. It seems to work well with several GHC versions.

@flhorizon
Copy link

@ak-coram Nice to know !

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

Successfully merging this pull request may close these issues.

3 participants