forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address concurrency issues in DequeRecycler close
This change addresses some concurrency issues that can occur when closing a DequeRecycler. The first issue that is addressed is a ConcurrentModificationException that can occur when using a locked DequeRecycler that is backed by an ArrayDeque. The ArrayDeque is not thread safe and requires external synchronization. In most cases the locked DequeRecycler handles this correctly but closing the DequeRecycler is not protected by the lock, which can lead to the ConcurrentModificationException if other threads are calling the obtain method. Additionally, the DequeRecycler close method used an iterator to go over all entries in the Deque and then later cleared them. The close method now uses pollFirst in a loop to empty the Deque and still execute the destroy method. Finally, the ConcurrentDequeRecycler had an overzealous assertion in the close method that the size of the Deque is equivalent to the externally tracked size. This assertion is not always going to be true due to the nature of the implementation. There is no lock guarding both the deque and the size value, so there is always a chance that the two could be wrong depending on ongoing requests. This assertion has been removed and a comment has been added that mentions there can be some discrepancies between the actual size of the deque and the externally tracked size. These issues may have always been present, but I believe the changes in Closes elastic#41683
- Loading branch information
Showing
4 changed files
with
74 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters