mirror of https://github.com/grpc/grpc-node.git
grpc-js: Fix handling of established connection drops in subchannel
This commit is contained in:
parent
974cb30a27
commit
327eecce3c
|
@ -242,30 +242,48 @@ export class Subchannel {
|
||||||
connectionOptions.servername = getDefaultAuthority(this.channelTarget);
|
connectionOptions.servername = getDefaultAuthority(this.channelTarget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.session = http2.connect(
|
const session = http2.connect(
|
||||||
addressScheme + this.subchannelAddress,
|
addressScheme + this.subchannelAddress,
|
||||||
connectionOptions
|
connectionOptions
|
||||||
);
|
);
|
||||||
this.session.unref();
|
this.session = session;
|
||||||
this.session.once('connect', () => {
|
session.unref();
|
||||||
|
/* For all of these events, check if the session at the time of the event
|
||||||
|
* is the same one currently attached to this subchannel, to ensure that
|
||||||
|
* old events from previous connection attempts cannot cause invalid state
|
||||||
|
* transitions. */
|
||||||
|
session.once('connect', () => {
|
||||||
|
if (this.session === session) {
|
||||||
this.transitionToState(
|
this.transitionToState(
|
||||||
[ConnectivityState.CONNECTING],
|
[ConnectivityState.CONNECTING],
|
||||||
ConnectivityState.READY
|
ConnectivityState.READY
|
||||||
);
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.session.once('close', () => {
|
session.once('close', () => {
|
||||||
|
if (this.session === session) {
|
||||||
this.transitionToState(
|
this.transitionToState(
|
||||||
[ConnectivityState.CONNECTING, ConnectivityState.READY],
|
[ConnectivityState.CONNECTING],
|
||||||
ConnectivityState.TRANSIENT_FAILURE
|
ConnectivityState.TRANSIENT_FAILURE
|
||||||
);
|
);
|
||||||
|
/* Transitioning directly to IDLE here should be OK because we are not
|
||||||
|
* doing any backoff, because a connection was established at some
|
||||||
|
* point */
|
||||||
|
this.transitionToState(
|
||||||
|
[ConnectivityState.READY],
|
||||||
|
ConnectivityState.IDLE
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.session.once('goaway', () => {
|
session.once('goaway', () => {
|
||||||
|
if (this.session === session) {
|
||||||
this.transitionToState(
|
this.transitionToState(
|
||||||
[ConnectivityState.CONNECTING, ConnectivityState.READY],
|
[ConnectivityState.CONNECTING, ConnectivityState.READY],
|
||||||
ConnectivityState.IDLE
|
ConnectivityState.IDLE
|
||||||
);
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.session.once('error', error => {
|
session.once('error', error => {
|
||||||
/* Do nothing here. Any error should also trigger a close event, which is
|
/* Do nothing here. Any error should also trigger a close event, which is
|
||||||
* where we want to handle that. */
|
* where we want to handle that. */
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue