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

Release a RefTracker even if the corresponding finaliser threw an error #513

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src-control/Control/RefCount.hs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ releaseRef ::
-> m ()
releaseRef ref@Ref{refobj} = do
assertNoDoubleRelease ref
decrementRefCounter (getRefCounter refobj)
releaseRefTracker ref
decrementRefCounter (getRefCounter refobj)

{-# COMPLETE DeRef #-}
#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
Expand Down
9 changes: 9 additions & 0 deletions test-control/Test/Control/RefCount.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tests = testGroup "Control.RefCount" [
, testProperty "prop_ref_never_released0" prop_ref_never_released0
, testProperty "prop_ref_never_released1" prop_ref_never_released1
, testProperty "prop_ref_never_released2" prop_ref_never_released2
, testProperty "prop_release_ref_exception" prop_release_ref_exception
#endif
]

Expand Down Expand Up @@ -176,5 +177,13 @@ expectRefNeverReleased :: RefException -> IO Property
expectRefNeverReleased RefNeverReleased{} = return (property True)
expectRefNeverReleased e =
return (counterexample (displayException e) $ property False)

-- | If a finaliser throws an exception, then the 'RefTracker' is still released
prop_release_ref_exception :: Property
prop_release_ref_exception = once $ ioProperty $ do
finalised <- newIORef False
ref <- newRef (writeIORef finalised True >> error "oops") TestObject
_ <- try @SomeException (releaseRef ref)
checkForgottenRefs
#endif

Loading