Home Bug Reports

Synchronous calls from AMI callback may lead to deadlock

allroallro Member Alex LeidermanOrganization: Cell2BetProject: Management Server

Let's consider Client, Server1 and Server2 and following logical flow.

1. Client calls asynchronously to function foo1 implemented by a servant deployed by Server1.
2. Response/exception is received by Client's AMI_foo1 callback object.
3. In ice_response/ice_exception implemented by AMI_foo1 we call synchronously to foo2 implemented by a servant deployed by Server2.

Now, if Client runs this logic in a loop it may lead to a deadlock (deadlock's probability grows with a loop counter limit).
Client may call foo2 asynchronously (no deadlock for loop_counter_limit=50000 according to my tests).
Please explain this behaviour.

Ice version: 3.3.1
System: Vista Premium 32bit
Compiler: VS 2005


  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff

    Thread starvation is quite likely in the situation you've described. Keep in mind that a thread from the client thread pool reads the reply messages and dispatches AMI callbacks. If you make a nested synchronous invocation from within an AMI callback, there may not be any threads remaining in the client thread pool to read the reply for that synchronous invocation, thus causing a deadlock.

    Consequently, you must either increase the maximum size of your client thread pool to be sufficiently large enough to guarantee that such a deadlock never occurs, or avoid the use of nested synchronous invocations altogether. In general we recommend the latter approach.

    Hope that helps,
Sign In or Register to comment.