title: Thread blocked indefinitely in an MVar operation
body: <p>I have been attempting to debug a problem when using multiple MVars, however to no luck.</p>
  
  <p>My code uses two MVars: one to store the servers current state, and another to pass network events to and from the client threads. However after connecting and disconnecting several times, the server stops sending data upon new clients connecting (presumably because the network events MVar is emptied for whatever reason) and eventually trips up with the error:  <code>*** Exception: thread blocked indefinitely in an MVar operation</code></p>
  
  <p>I have concluded the following in trying to debug this issue over the last few days:</p>
  
  <ol>
  <li>The functions used to modify the MVar(s) wont throw exceptions</li>
  <li>The problem does not occur until a client either connects, or connects then disconnects</li>
  <li>The issue seems to occur randomly (sometimes several clients can connect then disconnect, other times it happens right away)</li>
  </ol>
  
  <p>I have isolated the problem to three files:</p>
  
  <ol>
  <li><a href="https://github.com/Mattiemus/IMC-Server/blob/master/IMC.hs" rel="noreferrer">https://github.com/Mattiemus/IMC-Server/blob/master/IMC.hs</a> (the exception gets thrown in <code>sense</code>)</li>
  <li><a href="https://github.com/Mattiemus/IMC-Server/blob/master/IMC/Networking/Server.hs" rel="noreferrer">https://github.com/Mattiemus/IMC-Server/blob/master/IMC/Networking/Server.hs</a> (Modifined within <code>application</code> <code>handleClient</code>, and <code>cleanupClient</code>)</li>
  <li><a href="https://github.com/Mattiemus/IMC-Server/blob/master/IMC/Utilities/Concurrency.hs" rel="noreferrer">https://github.com/Mattiemus/IMC-Server/blob/master/IMC/Utilities/Concurrency.hs</a> (functions which push and pop to a list stored in an MVar)</li>
  </ol>
  
  <p>I am totally out of ideas, as I  only use modifyMVar and withMVar (so surely it should never be totally left empty) - my only assumption is that maybe an Exception is being thrown while modifying the MVar, however I think this is highly unlikely.</p>
  
  <p>Any help is appreciated, this problem has been bugging me for some time now.</p>