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

Commit 1e86021

Browse files
author
Joshua T Corbin
committed
ServiceDispatchHandler: drain incoming connections under .ensurePeerConnected
1 parent a78355b commit 1e86021

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

service-proxy.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,65 @@ function ensurePeerConnected(serviceName, peer, reason, now) {
635635
peer.clearDrain();
636636
}
637637

638-
peer.connectTo();
638+
peer.waitForIdentified(peer.connectTo(), onConnIded);
639+
640+
function onConnIded(err) {
641+
if (err) {
642+
self.logger.warn(
643+
'failed to ensure outgoing connection to service peer',
644+
self.extendLogInfo({
645+
error: err,
646+
peerHostPort: peer.hostPort,
647+
refreshReason: reason
648+
}));
649+
return;
650+
}
651+
peer.drain({
652+
reason: reason,
653+
direction: 'in',
654+
timeout: self.drainTimeout
655+
}, connectDrainDone);
656+
}
657+
658+
function connectDrainDone(err) {
659+
if (err &&
660+
err.type === 'tchannel.drain.peer.timed-out') {
661+
// TODO: stat?
662+
self.logger.warn(
663+
'forcibly closing drained peer',
664+
self.extendLogInfo({
665+
error: err,
666+
drainReason: reason
667+
})
668+
);
669+
err = null;
670+
}
671+
if (err) {
672+
self.logger.warn(
673+
'failed to drain incoming connections from service peer',
674+
self.extendLogInfo({
675+
error: err,
676+
peerHostPort: peer.hostPort
677+
})
678+
);
679+
peer.clearDrain();
680+
return;
681+
}
682+
peer.closeDrainedConnections(connectDrainCloseDone);
683+
}
684+
685+
function connectDrainCloseDone(err) {
686+
if (err) {
687+
self.logger.warn(
688+
'failed to close drained incoming connections from service peer',
689+
self.extendLogInfo({
690+
error: err,
691+
peerHostPort: peer.hostPort
692+
})
693+
);
694+
}
695+
peer.clearDrain();
696+
}
639697
};
640698

641699
ServiceDispatchHandler.prototype.getPartialRange =

0 commit comments

Comments
 (0)