@@ -68,6 +68,7 @@ namespace microLB
6868 }
6969 void Balancer::handle_queue ()
7070 {
71+ printf (" handle_queue\n " );
7172 // check waitq
7273 while (nodes.pool_size () > 0 && queue.empty () == false )
7374 {
@@ -95,11 +96,22 @@ namespace microLB
9596 }
9697 void Balancer::handle_connections ()
9798 {
99+ printf (" handle_connections\n " );
98100 // stop any rethrow timer since this is a de-facto retry
99101 if (this ->throw_retry_timer != Timers::UNUSED_ID) {
100102 Timers::stop (this ->throw_retry_timer );
101103 this ->throw_retry_timer = Timers::UNUSED_ID;
102104 }
105+
106+ // prune dead clients because the "number of clients" is being
107+ // used in a calculation right after this to determine how many
108+ // nodes to connect to
109+ auto new_end = std::remove_if (queue.begin (), queue.end (),
110+ [](Waiting& client) {
111+ return client.conn == nullptr || client.conn ->is_connected () == false ;
112+ });
113+ queue.erase (new_end, queue.end ());
114+
103115 // calculating number of connection attempts to create
104116 int np_connecting = nodes.pool_connecting ();
105117 int estimate = queue.size () - (np_connecting + nodes.pool_size ());
@@ -129,6 +141,7 @@ namespace microLB
129141 : conn(std::move(incoming)), total(0 )
130142 {
131143 assert (this ->conn != nullptr );
144+ assert (this ->conn ->is_connected ());
132145 // queue incoming data from clients not yet
133146 // assigned to a node
134147 this ->conn ->on_read (READQ_PER_CLIENT,
@@ -315,6 +328,13 @@ namespace microLB
315328 this ->active_timer = Timers::periodic (
316329 ACTIVE_INITIAL_PERIOD, ACTIVE_CHECK_PERIOD,
317330 {this , &Node::perform_active_check});
331+ LBOUT (" Node %s restarting active check (and is inactive)\n " ,
332+ this ->addr .to_string ().c_str ());
333+ }
334+ else
335+ {
336+ LBOUT (" Node %s still trying to connect...\n " ,
337+ this ->addr .to_string ().c_str ());
318338 }
319339 }
320340 }
@@ -367,12 +387,12 @@ namespace microLB
367387 this ->pool .push_back (std::make_unique<net::tcp::Stream>(conn));
368388 // stop any active check
369389 this ->stop_active_check ();
390+ // signal change in pool
391+ this ->pool_signal ();
370392 }
371393 else {
372394 this ->restart_active_check ();
373395 }
374- // signal change in pool
375- this ->pool_signal ();
376396 });
377397 }
378398 net::Stream_ptr Node::get_connection ()
0 commit comments