Solved

How to abort a call to a COM method?

Posted on 2009-07-02
5
913 Views
Last Modified: 2013-12-14
Hello Community,

I'm trying to stabilize a COM server that provides events via connection points. When I call IDispatch::Invoke() to trigger an event sink method on the client, I don't know how long the client needs to finish running this method - perhaps the client never returns...

Is there a way to abort such a call after a timeout? Or can I abort a call programmatically? The server seems to wait endlessly for the client to return. I've decoupled the part calling Invoke() from the rest of the application, so the application can continue to run even if a client is hanging.

Now I'm looking for a way to kill these hanging calls.

Can anyone give me hint how to solve that problem?

Thank you in advance!

Greetings,
Metacrawler
0
Comment
Question by:Metacrawler
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 24763153
You could put the Invoke to a thread and call TerminateThread if it timeouts. However, that probably will let open some resources and - depending on the actions done by the COM - even could corrupt your system (e. g. if some data halfly were written to a file). So, the TerminateThread should be the last resort and if you could move the termination into the COM method it would be better. Best would be if only the last hanging action was put into a own thread which was killed after timeout. Then, the dangers can be managed or even ignored. E. g. if the hanging action is the attempt to connect to a server, you could terminate that action without probs as the TCP/IP subsystem is safe regarding dying clients.
0
 

Author Comment

by:Metacrawler
ID: 24770486
Hello itsmeandnobodyelse,

thank you for your response. I thought terminating the thread hanging at the Invoke() is the only way to handle a hanging client, too. But there must be way to tell COM how to handle a hanging connection. That problem is not that rare, so there must be another way to abort the call.

It's a difficult problem, I know. But that's the reason why I ask you Experts :-)

Greetings,
Metacrawler

PS: I'll increase the number of point to 500. So feel encouraged to find a solution ;-)
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24770730
>>>> But there must be way to tell COM how to handle a hanging connection.

The good (or bad) with COM is that you got a pointer pointing directly to a function in the COM Server which you now can use to call other functions directly via pointer as well. So, AFAIK, there is no *instance* which was watching that and could *break* in case of hanging. You don't have such a mechanism when calling your own functions either.

You also should see that only a few COM servers actually will establish connections which might hang after. It isn't the task of the COM to prevent from hanging. It is the COM method you were calling which should provide a timeout or which you need to call in a thread to prevent from freezing the main thread.
0
 

Author Comment

by:Metacrawler
ID: 24770810
Ok, I understand.

But since I don't know how the clients are implemented, I don't know how a client behaves in some situations. The implementation of the server is the only thing I can influence. So I must rely on the clients implementation - I don't control - doing everything right... That is something causing my brain to ache ;-)

The server does some critical tasks and should continue to operate normally - even if a client does something really stupid ;-)

Greetings,
Metacrawler
0
 

Author Comment

by:Metacrawler
ID: 24771491
I've implemented the solution with TerminateThread() and it seems to work properly.

Thank you for your assistence, the points are yours :-)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now