diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index e302a81..82757f4 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -621,6 +621,8 @@
             {
                 m->max_peerid--;
             }
+
+            m->assigned_peer_ids--;
         }
 
         schedule_remove_entry(m->schedule, (struct schedule_entry *)mi);
@@ -749,7 +751,7 @@
 
     mi->context.c2.tls_multi->multi_state = CAS_NOT_CONNECTED;
 
-    if (hash_n_elements(m->hash) >= m->max_clients)
+    if (m->assigned_peer_ids >= m->max_clients)
     {
         msg(D_MULTI_ERRORS,
             "MULTI: new incoming connection would exceed maximum number of clients (%u)",
@@ -4219,6 +4221,8 @@
     {
         m->max_peerid = mi->context.c2.tls_multi->rx_peer_id;
     }
+
+    m->assigned_peer_ids++;
 }
 
 /**
diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h
index 5db7147..cc7ccd3 100644
--- a/src/openvpn/multi.h
+++ b/src/openvpn/multi.h
@@ -174,6 +174,8 @@
     uint32_t max_peerid;               /**< highest currently allocated peer-id
                                         * and maximum allocated/valid index in
                                         * instances */
+    uint32_t assigned_peer_ids;        /**< Number of peer-ids that are
+                                        *   currently assigned */
     struct hash *hash;                 /**< VPN tunnel instances indexed by real
                                         *   address of the remote peer. */
     struct hash *vhash;                /**< VPN tunnel instances indexed by
