My problem is - I use Scala and Akka - one of the jobs is to use an external API through third party SDK. The problem is I have no control over this SDK and, well, I should expect anything to happen inside, even infinite loop.
I "solved" the problem like this
Await.result( Future { sdk.makeSomeCall()}, 1.minute)
so my code won't block forever. However, I started to test this by stubbing makeSomeCall()
with simple Thread.sleep()
- and found that Await.result
does not actually kill a future, because the test execution continues for around 1.minute
and changes with this parameter.
I debugged a bit and found, that actually, Await.result
returns, however threads continue in the background, waiting for Thread.sleep
to finish.
I assume that my code just 'detach' from current Future and let it execute in its given thread - this may quickly lead to some starvation in production code.
Question is simple - how to make it proper - it means that after the timeout passes the new thread/Future will be terminated and all resources allocated by this code will be freed (I assume that SDK may make some mess, but this is not an issue now)