gabr42 / gabr42/OmniThreadLibrary
Possible bug in TOmniValueQueue
- Dominant language
- Pascal
- Stars
- 513
- Forks
- 147
- PR merge metrics
- No merged PRs in 30d
Description
No idea if I can make reproducible case out of this, most likely not, but I have situation when I put stuff in the Queue, canel the multithreaded process.
TOmniValueQueue.Destroy gets called, on FreeAndNil(FInnerQueue);
calls to the TOmniValueQueue.CollectionNotifyEvent starts firing, and the FInnerQueue is freed in this point.
made following change to the procedure
```
procedure TOmniValueQueue.CollectionNotifyEvent(Sender: TObject;
const Item: TOmniValue; Action: TCollectionNotification);
var
AfterCount: integer;
begin
// This method occurs within the critical section.
AfterCount := -1; // <- Change starts
if Assigned(FInnerQueue) then
AfterCount := FInnerQueue.Count; // <- Change ends
```
Maybe this should be handled earlier, or ion completely other way, in TOmniValueQueue or in my code. but it seems that this will get rid of Access Violation, or the destructor TOmniValueQueue.Destroy; should firs clear the Queue, before releasing FInnerQueue
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by inspecting TOmniValueQueue.Destroy and CollectionNotifyEvent, focusing on the FreeAndNil(FInnerQueue) path during multithreaded cancellation. Try to reproduce the access violation if possible and verify that notification callbacks cannot access the freed queue; done means the destruction path is safe under cancellation.
Written by the indexing model from the issue text.
Assessment
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100