Skip to content

Commit 1b7b646

Browse files
microlb: Handle exception when connect and terminate hack for unused backend connections
1 parent 08a8a28 commit 1b7b646

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

lib/microLB/micro_lb/balancer.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,12 @@ namespace microLB
259259
auto &session=get_session(idx);
260260

261261
// free session destroying potential unique ptr objects
262-
session.incoming =nullptr;
263-
session.outgoing=nullptr;
262+
session.incoming = nullptr;
263+
auto out_tcp = dynamic_cast<net::tcp::Stream*>(session.outgoing->bottom_transport())->tcp();
264+
session.outgoing = nullptr;
265+
// if we don't have anything to write to the backend, abort it.
266+
if(not out_tcp->sendq_size())
267+
out_tcp->abort();
264268
free_sessions.push_back(session.self);
265269
LBOUT("Session %d destroyed (total = %d)\n", session.self, session_cnt);
266270
}
@@ -359,7 +363,17 @@ namespace microLB
359363
}
360364
void Node::connect()
361365
{
362-
auto outgoing = this->stack.tcp().connect(this->addr);
366+
net::tcp::Connection_ptr outgoing;
367+
try
368+
{
369+
outgoing = this->stack.tcp().connect(this->addr);
370+
}
371+
catch(const net::TCP_error& err)
372+
{
373+
LBOUT("Got exception: %s\n", err.what());
374+
this->restart_active_check();
375+
return;
376+
}
363377
// connecting to node atm.
364378
this->connecting++;
365379
// retry timer when connect takes too long

0 commit comments

Comments
 (0)