diff --git a/src/comm.cpp b/src/comm.cpp
index a1078ba3328a6e68baf42d466da3f6ef23c18cc7..0cb3c142099e70afdda4d6cb58d1afb80cb90c58 100644
--- a/src/comm.cpp
+++ b/src/comm.cpp
@@ -261,6 +261,15 @@ void *CComm::comm_thread(void *param)
       }
       comm_dev->access_comm.exit();
     }catch(CException &e){
+      try{
+        comm_dev->hard_close();
+      }catch(CException &close){
+        std::cout << close.what() << std::endl;
+      }
+      /* flush the data queues */
+      comm_dev->receive_queue.flush();
+      /* change the current state */
+      comm_dev->state=created;
       comm_dev->access_comm.exit();
       std::cout << e.what() << std::endl;
       end=true;