Why does the number of instances of a pooled service drop below the initial pool size

I am creating a pooled service with an initial pool size of 10 and an infite timeout.

I also preinitialize the pool.

I see that the 10 instances are created upon startup but when the service is used the instances get destroyed.

Shouldn’t it keep the 10 instances at all times?

… and after a while, we have 0 left

FYI: I allow additional services to be created. I assume the timeout will then determine if these additional services get freed at some point

For remote calls, yes, they return the instance to the pool, and the value 10 remains.

For in-process calls, no. That is a bug on our side, it is fixed and will be in the next release.

In the meantime, return the instance to the class factory yourself instead of calling Engine.ReleaseLocalService:

// serviceName — the same name you pass to Engine.AcquireLocalService today
var factory = RemObjects.SDK.Server.Engine.ServiceManager.GetService(serviceName).ClassFactory;

var service = factory.AcquireInstance(sessionId);   // activates it
try
{
    // your call on the service instance
}
finally
{
    factory.ReleaseInstance(sessionId, service);    // deactivates and returns it to the pool
}

For LocalDataAdapter, acquire the instance the same way and assign it to the adapter’s ServiceInstance property an instance supplied from outside is not disposed by the adapter.

One thing to avoid until the fix: do not switch to PoolBehavior.Wait or Fail. The pool’s “in use” counter is leaked along with the instance, so Fail raises ObjectPoolExhaustedException and Wait blocks forever, even on an idle server.

The attached project runs both variants side by side against your installed Data Abstract open workaround and run.

PoolWorkaround.zip (2.1 KB)

Fixed. Fix will be in the next release.