IMHO the possible solution would be 
1) Remove all the IPC stuff and just immediately unload the document when all the windows are closed, assuming that only '‘no open window case’' is supported ATM. 
2) Support other cases in follow-up patches (to support for example the chat application that Alex has mentioned in the previous comment)