TimeObjectPool invalidation usurps pooled object level invalidation · Issue #9 · pomma89/objectpool · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 21, 2022. It is now read-only.
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;
The text was updated successfully, but these errors were encountered:
TimeObjectPool adds a multicast callback to validate the object in the context of timed expiration:
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.
The text was updated successfully, but these errors were encountered: