I have been attempting to debug a problem when using multiple MVars, however to no luck.
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:
*** Exception: thread blocked indefinitely in an MVar operation
I have concluded the following in trying to debug this issue over the last few days:
- The functions used to modify the MVar(s) wont throw exceptions
- The problem does not occur until a client either connects, or connects then disconnects
- The issue seems to occur randomly (sometimes several clients can connect then disconnect, other times it happens right away)
I have isolated the problem to three files:
- https://github.com/Mattiemus/IMC-Server/blob/master/IMC.hs (the exception gets thrown in
- https://github.com/Mattiemus/IMC-Server/blob/master/IMC/Networking/Server.hs (Modifined within
- https://github.com/Mattiemus/IMC-Server/blob/master/IMC/Utilities/Concurrency.hs (functions which push and pop to a list stored in an MVar)
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.
Any help is appreciated, this problem has been bugging me for some time now.