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

SWEEP: Lucene.Net.Store: Fixed several Dispose() methods so they are safe to be called multiple times #854

Merged
merged 7 commits into from
May 16, 2023

Conversation

NightOwl888
Copy link
Contributor

Fixes #841. Part of #265.

This adds an atomic CompareAndSetIsOpen(bool expect, bool update) method to BaseDirectory and BaseDirectoryWrapper that can be used to ensure only a single call to Dispose(bool) will succeed. This is the same method signature as J2N.Threading.Atomic.AtomicBoolean and can be used the same way (without the extra heap allocation).

protected override void Dispose(bool disposing)
{
    if (!CompareAndSetIsOpen(expect: true, update: false)) return;

    // Dispose unmanaged resources
    if (disposing)
    {
        // Dispose managed resources
    }
}

This fixes NRTCachingDirectory (as well as all other directories) so they don't throw exceptions when Dispose() is called multiple times.

This of course means that EnsureOpen() will be active immediately when Dispose() is first called, so be mindful of its usage when the Dispose() method needs to call local methods to clean up.

…n Dispose() is called multiple times. Also added checks to ensure an ObjectDisposedException is thrown by any method call after Dispose() is called. Fixed all other directory implementations and made the check atomic so only the first call to Dispose() is run. Fixes apache#841. Related to apache#265.
…FSDirectory): Upgraded all FSDirectories to allow multiple Dispose() calls on IndexInputSlicer and BufferedIndexInput subclasses. See apache#265.
@NightOwl888 NightOwl888 merged commit e9c47b2 into apache:master May 16, 2023
NightOwl888 added a commit that referenced this pull request Oct 25, 2024
* add release notes

* add changes

* more references to new beta

* more website changes for new beta

* Update supported .NET versions

* WIP on adding release notes, through #854 on 2023-05-16

* Finish updating changelog for beta 17

* Remove empty bullet

* Revert "more website changes for new beta"

This reverts commit 81bc9f4.

* Revert "more references to new beta"

This reverts commit 305a7d4.

* Revert "Update supported .NET versions"

This reverts commit f29a15e.

* Revert "add changes"

This reverts commit ea4f414.

* Release notes for 4.8.0-beta00017: Updated summary, added categories for New Features and Website and Docs to better organize the issues.

---------

Co-authored-by: Paul Irwin <paulirwin@gmail.com>
Co-authored-by: Shad Storhaug <shad@shadstorhaug.com>
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.

NRTCachingDirectory doesn't allow double dispose calls
1 participant