There are N Workers and one Master.Workers are unstable and frequently can hang up or die.If worker dies - it's ok because there will be error in callback in master.But if worker hangs - there's a problem - callback in master also will hangs indefinitely.And this is a problem, I need to kill those hanging callbacks in master.
Yes you are right my code isnt finished and need to ensure that callback will be called only once. But, my primary concern is memory leeks (maybe also descriptors leeks as it won't be released also). Is there a way to prevent those leaks and terminate hanging callbacks and release allocated resources?
Is it possible to do something like this?function safeCallToSomeRemoteService(callback){var remoteServiceResponded = falseunsafeCallToSomeRemoteService(function(err, data){remoteServiceResponded = truecallback(err, data)})setTimeout(function(){if(!remoteServiceResponded){somehow kill callback waiting for remote servicecallback(new Error("Remote service hanged!"))}}, 3000)}Or, if it's not possible, is it safe to just ignore such hanged callbacks, call callback on timeout and move on (while leaving hanging callback active)?
Maybe you can check if the client has a timeout parameter or other fallback strategies. If it does, you should trust the client that it performs the appropriate cleanup of the resources it uses.