Wednesday, December 16, 2015

Limiting COM ourproc server instances

A common approach to limit an application to single instance is to create a named kernel objects (mutex,semaphore etc) from main(). This is not always best method and may lead to freeze the client application in case of an outproc server. A typical case is the activation of outproc server from different users or users with different privileges.

An elementary feature of COM server is to launch the server during very first CoCreateInstance() call and  connect the subsequent calls to existing server. If  client calls are from different privileges(For example standard and administrator), it will try to launch multiple server instances and it is a security measure. So the second and subsequent calls will get blocked for 120 seconds and leads to application freeze. It will return failure after 120 seconds.

To limit COM server instance to one, there is another method which can be accomplished by modifying COM identity(.rgs file). By default all COM servers are with Launching User identity unless specified explicitly. This can be changed to This User with the user credentials which is advisable to retain security. Another option is The Interactive user. But it will create multiple instances if client is not in an interactive user session(For example call from Windows Service).

Keep an eye on your Native API prototype for interop calls

Few weeks back, we have observed "an unexpected process termination" crash in a WPF app. From the crash dump, provides below calls...