Skip to content
This repository was archived by the owner on Feb 18, 2021. It is now read-only.

Commit 20fc2d5

Browse files
author
Joshua T Corbin
committed
ServiceDispatchHandler: drain incoming connections under .ensurePeerConnected
1 parent c3fb687 commit 20fc2d5

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

service-proxy.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,58 @@ function ensurePeerConnected(serviceName, peer, reason, now) {
511511
return;
512512
}
513513

514-
peer.connectTo();
514+
peer.waitForIdentified(peer.connectTo(), onConnIded);
515+
516+
function onConnIded(err) {
517+
if (err) {
518+
self.logger.warn(
519+
'failed to ensure outgoing connection to service peer',
520+
self.extendLogInfo({
521+
error: err,
522+
peerHostPort: peer.hostPort,
523+
refreshReason: reason
524+
}));
525+
return;
526+
}
527+
peer.drain({
528+
reason: reason,
529+
direction: 'in',
530+
timeout: self.drainTimeout
531+
}, connectDrainDone);
532+
}
533+
534+
function connectDrainDone(err) {
535+
if (err &&
536+
err.type === 'tchannel.drain.peer.timed-out') {
537+
// TODO: stat?
538+
self.logger.warn('forcibly closing drained peer', self.extendLogInfo({
539+
error: err,
540+
drainReason: reason
541+
}));
542+
err = null;
543+
}
544+
if (err) {
545+
self.logger.warn(
546+
'failed to drain incoming connections from service peer', self.extendLogInfo({
547+
error: err,
548+
peerHostPort: peer.hostPort
549+
}));
550+
peer.clearDrain();
551+
return;
552+
}
553+
peer.closeDrainedConnections(connectDrainCloseDone);
554+
}
555+
556+
function connectDrainCloseDone(err) {
557+
if (err) {
558+
self.logger.warn(
559+
'failed to close drained incoming connections from service peer', self.extendLogInfo({
560+
error: err,
561+
peerHostPort: peer.hostPort
562+
}));
563+
}
564+
peer.clearDrain();
565+
}
515566
};
516567

517568
ServiceDispatchHandler.prototype.computePartialRange =

0 commit comments

Comments
 (0)