Remove custom reference counting logic. #52
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch removes additional reference counting logic in C that normally the GHC RTS would handle internally by the use of finalizers. I believe this additional reference counting logic is responsible for the bugs seen when compiling with
-threaded
in #35 when working withresource-pool
.The problem
On later versions of GHC (
8.6.x
and above), when executables are compiled with-threaded
and run with+RTS -N -RTS
a double free error can occur. I was not able to reproduce this error without using-threaded
on the aforementioned GHC versions. This problem manifests itself in the below code (see #35 as well).Error
The patch
This PR does the following:
safe
instead ofunsafe
calls.libpq
finalizers when refs die.Test cases
Was able to use an old version of
QuickCheck
to compiletestpack
and run thehdbc-postgresql
test suite namedruntests
to produce 0 errors (compiling with-threaded
and using all available cores via-N
onGHC 8.8.4
).Furthermore, this seems to fix the following issues in orville and #35 , when used with @bos 's
resource-pool
package.result
and for
orville
result
This code is obviously very sensitive and needs a lot of eyes on it before this PR can be approved and merged.