8000 TimeObjectPool invalidation usurps pooled object level invalidation · Issue #9 · pomma89/objectpool · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on May 21, 2022. It is now read-only.

TimeObjectPool invalidation usurps pooled object level invalidation #9

Closed
ghost opened this issue May 11, 2019 · 2 comments
Closed
8000
Assignees
Labels

Comments

@ghost
Copy link
ghost commented May 11, 2019

TimeObjectPool adds a multicast callback to validate the object in the context of timed expiration:

pooledObject.OnValidateObject += (ctx) =>
        {
            // An item which have been last used before following threshold will be destroyed.
            var threshold = DateTime.UtcNow - _timeout;
            return !(ctx.PooledObjectInfo.Payload is DateTime lastUsage && lastUsage < threshold);
        };

The problem here is this usurps any existing function added to this callback by the pooled object itself. So the first delegate added by the object may report false (invalid object), but this call will always return its result to the caller as it's the last delegate in the invocation list (since we've made this a multicast function call). The end result are invalid objects added to or returned by the pool as the object level invalidation result is always ignored.

A fix for this can be made in the caller for the validation - PooledObject::ValidateObject(). Invoke the multicast callback by calling the delegates individually and return false if any of them return false.

// return OnValidateObject(validationContext);
if (OnValidateObject.GetInvocationList().Cast<Func<PooledObjectValidationContext, bool>>().Any(valDelegate => !valDelegate(validationContext)))
 return false;
pomma89 added a commit that referenced this issue May 12, 2019
@pomma89
Copy link
Owner
pomma89 commented May 12, 2019

Done. I published a new package: https://www.nuget.org/packages/CodeProject.ObjectPool/3.2.3

Let me know if I misunderstood what you suggested.

Thanks!

@pomma89 pomma89 closed this as completed May 12, 2019
@ghost
Copy link
Author
ghost commented May 12, 2019 via email

@pomma89 pomma89 self-assigned this Aug 23, 2019
@pomma89 pomma89 added the bug label Aug 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant
0