I'm working with an application that services several types of clients, some of them 'impatient'. By that I mean they will drop the connection and resend the request after a relatively short amount of time.
My application makes use of services outside my control. Sometimes these services take longer to fulfill than my client will wait.
My question-- I'd like to be able to send the client a response that says 'the request took longer than expected' and rollback the remnants of the transaction if we get a long running one. I'd like to do this after a set amount of time (say 4 seconds). The problem: I can't send my 'sorry I'm late' response in 4 seconds if one of my externally-provided services takes 10 seconds to execute. (Say I'm 2 seconds into the transaction, then start the call to the slow external service. I won't get a chance to rollback and send the I'm-sorry until 10 seconds later, already 12 seconds into the whole transaction.)
I've thought about spinning another thread to act as a traffic cop, but it seems the information-sharing might get a little tricky. (Do you use the database to decide if the transaction made it in time or not? Do you leave a clue to rollback for the primary thread to decide if it's late? It seems like there are two transactions there, so the potential for inconsistency exists.)
If anyone has any thoughts around this topic, I'd love to hear them!