Index: /trunk/FACT++/src/EventBuilder.cc
===================================================================
--- /trunk/FACT++/src/EventBuilder.cc	(revision 17678)
+++ /trunk/FACT++/src/EventBuilder.cc	(revision 17679)
@@ -357,7 +357,9 @@
         factPrintf(MessageImp::kInfo, "Closed socket %d (%d)", sockId, socket);
 
+    // Set the socket to "not connected"
     socket = -1;
     connected = false;
     activeSockets--;
+    bufLen = 0;
 }
 
@@ -645,4 +647,6 @@
     evt->nRoi   = nRoi[0];
     evt->nRoiTM = nRoi[8];
+
+    //evt->firstBoard = rd.sockId;
 
     const bool newrun = actrun->runId != rd.H.runnumber;
@@ -1308,5 +1312,5 @@
             {
                 factPrintf(MessageImp::kError, "Got event %5d from board %3d (i=%3d, len=%5d) twice.",
-                           evt->evNum, rs->sockId, rs->sockId, rs->len());
+                           evt->evNum, rs->sockId, jj, rs->len());
                 // FIXME: What to do with the validity flag?
                 continue; // Continue reading next header
@@ -1354,4 +1358,6 @@
                     rd[ib].relBytes += uint32_t((*it)->FADhead[ib].package_length)*2;
 
+                // The counter must be increased _before_ the pop_front,
+                // otherwise the counter is invalidated by the pop_front!
                 it++;
                 evtCtrl.pop_front();
@@ -1416,15 +1422,23 @@
             const shared_ptr<EVT_CTRL2> &evt = *it;
 
-            // If there was no memory, it is possible that no header has been processed yet
-            // but the event already exists. What we want to check here are only
-            // if from partially complete events a baord is missing, not
-            // whether the whole event is missing
-            if (!evt->valid())
-                continue;
-
             // The first event is the oldest. If the first event within the
             // timeout window was received, we can stop searching further.
             if (evt->time.tv_sec+g_evtTimeout>=actTime)
                 break;
+
+            // The counter must be increased _before_ the pop_front,
+            // otherwise the counter is invalidated by the pop_front!
+            it++;
+
+            // This timeout is caused because complete data from one or more
+            // boards has been received, but the memory could not be allocated.
+            // There is no reason why we should not go on waiting for
+            // memory to become free. However, the FADs will disconnect
+            // after 60s due to their keep-alive timeout, but the event builder
+            // will still wait for memory to become available.
+            // Currently, the only possibility to free the memory from the
+            // evtCtrl to restart the event builder (STOP/START).
+            if (!evt->valid())
+                continue;
 
             // This will result in the emission of a dim service.
@@ -1434,9 +1448,9 @@
             factReportIncomplete(rep);
 
+            // At least the data from one boards is complete...
             // package_len is 0 when nothing was received from this board
             for (int ib=0; ib<40; ib++)
-                rd[ib].relBytes += uint32_t((*it)->FADhead[ib].package_length)*2;
-
-            it++;
+                rd[ib].relBytes += uint32_t(evt->FADhead[ib].package_length)*2;
+
             evtCtrl.pop_front();
         }
Index: /trunk/FACT++/src/EventBuilder.h
===================================================================
--- /trunk/FACT++/src/EventBuilder.h	(revision 17678)
+++ /trunk/FACT++/src/EventBuilder.h	(revision 17679)
@@ -120,4 +120,5 @@
     uint32_t  fadLen;
 
+    //uint16_t  firstBoard; // first board from which data was received
     uint16_t  nBoard;
     int16_t   board[NBOARDS];
