How to call release from COM server

一个人想着一个人 提交于 2019-12-06 13:20:29

COM periodically pings clients to see if they are still alive and runs down interfaces from dead clients. So your server will find out eventually.

That's a vulnerability that exists whenever you have two or processes interop with each other. One of them dies and the other one keeps running, unaware that there will never be another request again from the dead process. In the case of an out-of-process COM server, nobody is going to call IUnknown::Release() to get the object destroyed. COM does not otherwise have a built-in fix for that problem. An in-process server doesn't have this problem, the crashed process takes the server out as well. Which is a problem too, no nice cleanup, but easier to deal with.

Getting the server to recover from this is something you'll have to add yourself. You could, say, have the client pass its process ID so that the server can obtain the process handle and detect when the client falls over with WaitForMultipleHandles(). Assuming they both live on the machine, that's certainly not a COM requirement and not something the server can find out.

COM will release the server-side object in an out-proc server some time after the client dies but only if there's no call executing in that object. This is the key - COM can't possibly stop a call in progress. So the solution is to make methods short-running and guaranteed to finish in some short reasonable time like several seconds. This way once the client dies no new calls arrive from it and after some time the call in progress end naturally and then after a timeout COM releases the objects in the server and the server can stop naturally.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!