@grpc/grpc-js
Advanced tools
Comparing version 1.8.8 to 1.8.9
export type Deadline = Date | number; | ||
export declare function minDeadline(...deadlineList: Deadline[]): Deadline; | ||
export declare function getDeadlineTimeoutString(deadline: Deadline): string; | ||
/** | ||
* Get the timeout value that should be passed to setTimeout now for the timer | ||
* to end at the deadline. For any deadline before now, the timer should end | ||
* immediately, represented by a value of 0. For any deadline more than | ||
* MAX_TIMEOUT_TIME milliseconds in the future, a timer cannot be set that will | ||
* end at that time, so it is treated as infinitely far in the future. | ||
* @param deadline | ||
* @returns | ||
*/ | ||
export declare function getRelativeTimeout(deadline: Deadline): number; | ||
export declare function deadlineToString(deadline: Deadline): string; |
@@ -19,3 +19,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getRelativeTimeout = exports.getDeadlineTimeoutString = exports.minDeadline = void 0; | ||
exports.deadlineToString = exports.getRelativeTimeout = exports.getDeadlineTimeoutString = exports.minDeadline = void 0; | ||
function minDeadline(...deadlineList) { | ||
@@ -53,8 +53,48 @@ let minValue = Infinity; | ||
exports.getDeadlineTimeoutString = getDeadlineTimeoutString; | ||
/** | ||
* See https://nodejs.org/api/timers.html#settimeoutcallback-delay-args | ||
* In particular, "When delay is larger than 2147483647 or less than 1, the | ||
* delay will be set to 1. Non-integer delays are truncated to an integer." | ||
* This number of milliseconds is almost 25 days. | ||
*/ | ||
const MAX_TIMEOUT_TIME = 2147483647; | ||
/** | ||
* Get the timeout value that should be passed to setTimeout now for the timer | ||
* to end at the deadline. For any deadline before now, the timer should end | ||
* immediately, represented by a value of 0. For any deadline more than | ||
* MAX_TIMEOUT_TIME milliseconds in the future, a timer cannot be set that will | ||
* end at that time, so it is treated as infinitely far in the future. | ||
* @param deadline | ||
* @returns | ||
*/ | ||
function getRelativeTimeout(deadline) { | ||
const deadlineMs = deadline instanceof Date ? deadline.getTime() : deadline; | ||
const now = new Date().getTime(); | ||
return deadlineMs - now; | ||
const timeout = deadlineMs - now; | ||
if (timeout < 0) { | ||
return 0; | ||
} | ||
else if (timeout > MAX_TIMEOUT_TIME) { | ||
return Infinity; | ||
} | ||
else { | ||
return timeout; | ||
} | ||
} | ||
exports.getRelativeTimeout = getRelativeTimeout; | ||
function deadlineToString(deadline) { | ||
if (deadline instanceof Date) { | ||
return deadline.toISOString(); | ||
} | ||
else { | ||
const dateDeadline = new Date(deadline); | ||
if (Number.isNaN(dateDeadline.getTime())) { | ||
return '' + deadline; | ||
} | ||
else { | ||
return dateDeadline.toISOString(); | ||
} | ||
} | ||
} | ||
exports.deadlineToString = deadlineToString; | ||
//# sourceMappingURL=deadline.js.map |
@@ -14,2 +14,3 @@ import { ChannelCredentials } from './channel-credentials'; | ||
import { RetryingCall } from './retrying-call'; | ||
import { BaseSubchannelWrapper, SubchannelInterface } from './subchannel-interface'; | ||
interface NoneConfigResult { | ||
@@ -27,2 +28,10 @@ type: 'NONE'; | ||
type GetConfigResult = NoneConfigResult | SuccessConfigResult | ErrorConfigResult; | ||
declare class ChannelSubchannelWrapper extends BaseSubchannelWrapper implements SubchannelInterface { | ||
private channel; | ||
private stateListeners; | ||
private refCount; | ||
constructor(childSubchannel: SubchannelInterface, channel: InternalChannel); | ||
ref(): void; | ||
unref(): void; | ||
} | ||
export declare class InternalChannel { | ||
@@ -63,2 +72,4 @@ private readonly credentials; | ||
private retryBufferTracker; | ||
private keepaliveTime; | ||
private wrappedSubchannels; | ||
private readonly channelzEnabled; | ||
@@ -77,2 +88,4 @@ private originalTarget; | ||
private updateState; | ||
throttleKeepalive(newKeepaliveTime: number): void; | ||
removeWrappedSubchannel(wrappedSubchannel: ChannelSubchannelWrapper): void; | ||
doPick(metadata: Metadata, extraPickInfo: { | ||
@@ -79,0 +92,0 @@ [key: string]: string; |
@@ -35,2 +35,3 @@ "use strict"; | ||
const load_balancing_call_1 = require("./load-balancing-call"); | ||
const deadline_1 = require("./deadline"); | ||
const resolving_call_1 = require("./resolving-call"); | ||
@@ -40,2 +41,3 @@ const call_number_1 = require("./call-number"); | ||
const retrying_call_1 = require("./retrying-call"); | ||
const subchannel_interface_1 = require("./subchannel-interface"); | ||
/** | ||
@@ -48,5 +50,30 @@ * See https://nodejs.org/api/timers.html#timers_setinterval_callback_delay_args | ||
const DEFAULT_PER_RPC_RETRY_BUFFER_SIZE_BYTES = 1 << 20; // 1 MB | ||
class ChannelSubchannelWrapper extends subchannel_interface_1.BaseSubchannelWrapper { | ||
constructor(childSubchannel, channel) { | ||
super(childSubchannel); | ||
this.channel = channel; | ||
this.stateListeners = []; | ||
this.refCount = 0; | ||
childSubchannel.addConnectivityStateListener((subchannel, previousState, newState, keepaliveTime) => { | ||
channel.throttleKeepalive(keepaliveTime); | ||
for (const listener of this.stateListeners) { | ||
listener(this, previousState, newState, keepaliveTime); | ||
} | ||
}); | ||
} | ||
ref() { | ||
this.child.ref(); | ||
this.refCount += 1; | ||
} | ||
unref() { | ||
this.child.unref(); | ||
this.refCount -= 1; | ||
if (this.refCount <= 0) { | ||
this.channel.removeWrappedSubchannel(this); | ||
} | ||
} | ||
} | ||
class InternalChannel { | ||
constructor(target, credentials, options) { | ||
var _a, _b, _c, _d, _e, _f; | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
this.credentials = credentials; | ||
@@ -72,2 +99,3 @@ this.options = options; | ||
this.currentResolutionError = null; | ||
this.wrappedSubchannels = new Set(); | ||
// Channelz info | ||
@@ -122,9 +150,13 @@ this.channelzEnabled = true; | ||
this.retryBufferTracker = new retrying_call_1.MessageBufferTracker((_d = options['grpc.retry_buffer_size']) !== null && _d !== void 0 ? _d : DEFAULT_RETRY_BUFFER_SIZE_BYTES, (_e = options['grpc.per_rpc_retry_buffer_size']) !== null && _e !== void 0 ? _e : DEFAULT_PER_RPC_RETRY_BUFFER_SIZE_BYTES); | ||
this.keepaliveTime = (_f = options['grpc.keepalive_time_ms']) !== null && _f !== void 0 ? _f : -1; | ||
const channelControlHelper = { | ||
createSubchannel: (subchannelAddress, subchannelArgs) => { | ||
const subchannel = this.subchannelPool.getOrCreateSubchannel(this.target, subchannelAddress, Object.assign({}, this.options, subchannelArgs), this.credentials); | ||
subchannel.throttleKeepalive(this.keepaliveTime); | ||
if (this.channelzEnabled) { | ||
this.channelzTrace.addTrace('CT_INFO', 'Created subchannel or used existing subchannel', subchannel.getChannelzRef()); | ||
} | ||
return subchannel; | ||
const wrappedSubchannel = new ChannelSubchannelWrapper(subchannel, this); | ||
this.wrappedSubchannels.add(wrappedSubchannel); | ||
return wrappedSubchannel; | ||
}, | ||
@@ -202,3 +234,3 @@ updateState: (connectivityState, picker) => { | ||
const error = new Error(); | ||
(0, logging_1.trace)(constants_1.LogVerbosity.DEBUG, 'channel_stacktrace', '(' + this.channelzRef.id + ') ' + 'Channel constructed \n' + ((_f = error.stack) === null || _f === void 0 ? void 0 : _f.substring(error.stack.indexOf('\n') + 1))); | ||
(0, logging_1.trace)(constants_1.LogVerbosity.DEBUG, 'channel_stacktrace', '(' + this.channelzRef.id + ') ' + 'Channel constructed \n' + ((_g = error.stack) === null || _g === void 0 ? void 0 : _g.substring(error.stack.indexOf('\n') + 1))); | ||
} | ||
@@ -270,2 +302,13 @@ getChannelzInfo() { | ||
} | ||
throttleKeepalive(newKeepaliveTime) { | ||
if (newKeepaliveTime > this.keepaliveTime) { | ||
this.keepaliveTime = newKeepaliveTime; | ||
for (const wrappedSubchannel of this.wrappedSubchannels) { | ||
wrappedSubchannel.throttleKeepalive(newKeepaliveTime); | ||
} | ||
} | ||
} | ||
removeWrappedSubchannel(wrappedSubchannel) { | ||
this.wrappedSubchannels.delete(wrappedSubchannel); | ||
} | ||
doPick(metadata, extraPickInfo) { | ||
@@ -338,3 +381,3 @@ return this.currentPicker.pick({ metadata: metadata, extraPickInfo: extraPickInfo }); | ||
'", deadline=' + | ||
deadline); | ||
(0, deadline_1.deadlineToString)(deadline)); | ||
const finalOptions = { | ||
@@ -341,0 +384,0 @@ deadline: deadline, |
@@ -157,7 +157,7 @@ "use strict"; | ||
this.childSubchannelState = childSubchannel.getConnectivityState(); | ||
childSubchannel.addConnectivityStateListener((subchannel, previousState, newState) => { | ||
childSubchannel.addConnectivityStateListener((subchannel, previousState, newState, keepaliveTime) => { | ||
this.childSubchannelState = newState; | ||
if (!this.ejected) { | ||
for (const listener of this.stateListeners) { | ||
listener(this, previousState, newState); | ||
listener(this, previousState, newState, keepaliveTime); | ||
} | ||
@@ -213,3 +213,3 @@ } | ||
for (const listener of this.stateListeners) { | ||
listener(this, this.childSubchannelState, connectivity_state_1.ConnectivityState.TRANSIENT_FAILURE); | ||
listener(this, this.childSubchannelState, connectivity_state_1.ConnectivityState.TRANSIENT_FAILURE, -1); | ||
} | ||
@@ -220,3 +220,3 @@ } | ||
for (const listener of this.stateListeners) { | ||
listener(this, connectivity_state_1.ConnectivityState.TRANSIENT_FAILURE, this.childSubchannelState); | ||
listener(this, connectivity_state_1.ConnectivityState.TRANSIENT_FAILURE, this.childSubchannelState, -1); | ||
} | ||
@@ -223,0 +223,0 @@ } |
@@ -67,5 +67,5 @@ "use strict"; | ||
clearTimeout(this.deadlineTimer); | ||
this.trace('Deadline: ' + this.deadline); | ||
if (this.deadline !== Infinity) { | ||
const timeout = (0, deadline_1.getRelativeTimeout)(this.deadline); | ||
this.trace('Deadline: ' + (0, deadline_1.deadlineToString)(this.deadline)); | ||
const timeout = (0, deadline_1.getRelativeTimeout)(this.deadline); | ||
if (timeout !== Infinity) { | ||
this.trace('Deadline will be reached in ' + timeout + 'ms'); | ||
@@ -72,0 +72,0 @@ const handleDeadline = () => { |
import { SubchannelRef } from "./channelz"; | ||
import { ConnectivityState } from "./connectivity-state"; | ||
import { Subchannel } from "./subchannel"; | ||
export type ConnectivityStateListener = (subchannel: SubchannelInterface, previousState: ConnectivityState, newState: ConnectivityState) => void; | ||
export type ConnectivityStateListener = (subchannel: SubchannelInterface, previousState: ConnectivityState, newState: ConnectivityState, keepaliveTime: number) => void; | ||
/** | ||
@@ -20,2 +20,3 @@ * This is an interface for load balancing policies to use to interact with | ||
getAddress(): string; | ||
throttleKeepalive(newKeepaliveTime: number): void; | ||
ref(): void; | ||
@@ -37,2 +38,3 @@ unref(): void; | ||
getAddress(): string; | ||
throttleKeepalive(newKeepaliveTime: number): void; | ||
ref(): void; | ||
@@ -39,0 +41,0 @@ unref(): void; |
@@ -39,2 +39,5 @@ "use strict"; | ||
} | ||
throttleKeepalive(newKeepaliveTime) { | ||
this.child.throttleKeepalive(newKeepaliveTime); | ||
} | ||
ref() { | ||
@@ -41,0 +44,0 @@ this.child.ref(); |
@@ -39,3 +39,3 @@ import { ChannelCredentials } from './channel-credentials'; | ||
private backoffTimeout; | ||
private keepaliveTimeMultiplier; | ||
private keepaliveTime; | ||
/** | ||
@@ -118,2 +118,3 @@ * Tracks channels and subchannel pools with references to this subchannel | ||
getRealSubchannel(): this; | ||
throttleKeepalive(newKeepaliveTime: number): void; | ||
} |
@@ -44,2 +44,3 @@ "use strict"; | ||
constructor(channelTarget, subchannelAddress, options, credentials, connector) { | ||
var _a; | ||
this.channelTarget = channelTarget; | ||
@@ -70,3 +71,2 @@ this.subchannelAddress = subchannelAddress; | ||
this.stateListeners = []; | ||
this.keepaliveTimeMultiplier = 1; | ||
/** | ||
@@ -90,2 +90,3 @@ * Tracks channels and subchannel pools with references to this subchannel | ||
this.subchannelAddressString = (0, subchannel_address_1.subchannelAddressToString)(subchannelAddress); | ||
this.keepaliveTime = (_a = options['grpc.keepalive_time_ms']) !== null && _a !== void 0 ? _a : -1; | ||
if (options['grpc.enable_channelz'] === 0) { | ||
@@ -137,3 +138,3 @@ this.channelzEnabled = false; | ||
if (options['grpc.keepalive_time_ms']) { | ||
const adjustedKeepaliveTime = Math.min(options['grpc.keepalive_time_ms'] * this.keepaliveTimeMultiplier, KEEPALIVE_MAX_TIME_MS); | ||
const adjustedKeepaliveTime = Math.min(this.keepaliveTime, KEEPALIVE_MAX_TIME_MS); | ||
options = Object.assign(Object.assign({}, options), { 'grpc.keepalive_time_ms': adjustedKeepaliveTime }); | ||
@@ -149,5 +150,5 @@ } | ||
this.transitionToState([connectivity_state_1.ConnectivityState.READY], connectivity_state_1.ConnectivityState.IDLE); | ||
if (tooManyPings) { | ||
this.keepaliveTimeMultiplier *= 2; | ||
logging.log(constants_1.LogVerbosity.ERROR, `Connection to ${(0, uri_parser_1.uriToString)(this.channelTarget)} at ${this.subchannelAddressString} rejected by server because of excess pings. Increasing ping interval multiplier to ${this.keepaliveTimeMultiplier} ms`); | ||
if (tooManyPings && this.keepaliveTime > 0) { | ||
this.keepaliveTime *= 2; | ||
logging.log(constants_1.LogVerbosity.ERROR, `Connection to ${(0, uri_parser_1.uriToString)(this.channelTarget)} at ${this.subchannelAddressString} rejected by server because of excess pings. Increasing ping interval to ${this.keepaliveTime} ms`); | ||
} | ||
@@ -217,3 +218,3 @@ }); | ||
for (const listener of [...this.stateListeners]) { | ||
listener(this, previousState, newState); | ||
listener(this, previousState, newState, this.keepaliveTime); | ||
} | ||
@@ -334,4 +335,9 @@ return true; | ||
} | ||
throttleKeepalive(newKeepaliveTime) { | ||
if (newKeepaliveTime > this.keepaliveTime) { | ||
this.keepaliveTime = newKeepaliveTime; | ||
} | ||
} | ||
} | ||
exports.Subchannel = Subchannel; | ||
//# sourceMappingURL=subchannel.js.map |
@@ -48,3 +48,3 @@ "use strict"; | ||
*/ | ||
this.keepaliveTimeMs = KEEPALIVE_MAX_TIME_MS; | ||
this.keepaliveTimeMs = -1; | ||
/** | ||
@@ -265,2 +265,5 @@ * The amount of time to wait for an acknowledgement after sending a ping | ||
var _a, _b; | ||
if (this.keepaliveTimeMs < 0) { | ||
return; | ||
} | ||
this.keepaliveIntervalId = setInterval(() => { | ||
@@ -267,0 +270,0 @@ this.sendPing(); |
{ | ||
"name": "@grpc/grpc-js", | ||
"version": "1.8.8", | ||
"version": "1.8.9", | ||
"description": "gRPC Library for Node - pure JS implementation", | ||
@@ -5,0 +5,0 @@ "homepage": "https://grpc.io/", |
@@ -54,6 +54,43 @@ /* | ||
/** | ||
* See https://nodejs.org/api/timers.html#settimeoutcallback-delay-args | ||
* In particular, "When delay is larger than 2147483647 or less than 1, the | ||
* delay will be set to 1. Non-integer delays are truncated to an integer." | ||
* This number of milliseconds is almost 25 days. | ||
*/ | ||
const MAX_TIMEOUT_TIME = 2147483647; | ||
/** | ||
* Get the timeout value that should be passed to setTimeout now for the timer | ||
* to end at the deadline. For any deadline before now, the timer should end | ||
* immediately, represented by a value of 0. For any deadline more than | ||
* MAX_TIMEOUT_TIME milliseconds in the future, a timer cannot be set that will | ||
* end at that time, so it is treated as infinitely far in the future. | ||
* @param deadline | ||
* @returns | ||
*/ | ||
export function getRelativeTimeout(deadline: Deadline) { | ||
const deadlineMs = deadline instanceof Date ? deadline.getTime() : deadline; | ||
const now = new Date().getTime(); | ||
return deadlineMs - now; | ||
const timeout = deadlineMs - now; | ||
if (timeout < 0) { | ||
return 0; | ||
} else if (timeout > MAX_TIMEOUT_TIME) { | ||
return Infinity | ||
} else { | ||
return timeout; | ||
} | ||
} | ||
export function deadlineToString(deadline: Deadline): string { | ||
if (deadline instanceof Date) { | ||
return deadline.toISOString(); | ||
} else { | ||
const dateDeadline = new Date(deadline); | ||
if (Number.isNaN(dateDeadline.getTime())) { | ||
return '' + deadline; | ||
} else { | ||
return dateDeadline.toISOString(); | ||
} | ||
} | ||
} |
@@ -49,3 +49,3 @@ /* | ||
import { SubchannelCall } from './subchannel-call'; | ||
import { Deadline, getDeadlineTimeoutString } from './deadline'; | ||
import { Deadline, deadlineToString, getDeadlineTimeoutString } from './deadline'; | ||
import { ResolvingCall } from './resolving-call'; | ||
@@ -55,2 +55,3 @@ import { getNextCallNumber } from './call-number'; | ||
import { MessageBufferTracker, RetryingCall, RetryThrottler } from './retrying-call'; | ||
import { BaseSubchannelWrapper, ConnectivityStateListener, SubchannelInterface } from './subchannel-interface'; | ||
@@ -89,2 +90,29 @@ /** | ||
class ChannelSubchannelWrapper extends BaseSubchannelWrapper implements SubchannelInterface { | ||
private stateListeners: ConnectivityStateListener[] = []; | ||
private refCount = 0; | ||
constructor(childSubchannel: SubchannelInterface, private channel: InternalChannel) { | ||
super(childSubchannel); | ||
childSubchannel.addConnectivityStateListener((subchannel, previousState, newState, keepaliveTime) => { | ||
channel.throttleKeepalive(keepaliveTime); | ||
for (const listener of this.stateListeners) { | ||
listener(this, previousState, newState, keepaliveTime); | ||
} | ||
}); | ||
} | ||
ref(): void { | ||
this.child.ref(); | ||
this.refCount += 1; | ||
} | ||
unref(): void { | ||
this.child.unref(); | ||
this.refCount -= 1; | ||
if (this.refCount <= 0) { | ||
this.channel.removeWrappedSubchannel(this); | ||
} | ||
} | ||
} | ||
export class InternalChannel { | ||
@@ -122,4 +150,6 @@ | ||
*/ | ||
private currentResolutionError: StatusObject | null = null; | ||
private retryBufferTracker: MessageBufferTracker; | ||
private currentResolutionError: StatusObject | null = null; | ||
private retryBufferTracker: MessageBufferTracker; | ||
private keepaliveTime: number; | ||
private wrappedSubchannels: Set<ChannelSubchannelWrapper> = new Set(); | ||
@@ -197,2 +227,3 @@ // Channelz info | ||
); | ||
this.keepaliveTime = options['grpc.keepalive_time_ms'] ?? -1; | ||
const channelControlHelper: ChannelControlHelper = { | ||
@@ -209,6 +240,9 @@ createSubchannel: ( | ||
); | ||
subchannel.throttleKeepalive(this.keepaliveTime); | ||
if (this.channelzEnabled) { | ||
this.channelzTrace.addTrace('CT_INFO', 'Created subchannel or used existing subchannel', subchannel.getChannelzRef()); | ||
} | ||
return subchannel; | ||
const wrappedSubchannel = new ChannelSubchannelWrapper(subchannel, this); | ||
this.wrappedSubchannels.add(wrappedSubchannel); | ||
return wrappedSubchannel; | ||
}, | ||
@@ -378,2 +412,15 @@ updateState: (connectivityState: ConnectivityState, picker: Picker) => { | ||
throttleKeepalive(newKeepaliveTime: number) { | ||
if (newKeepaliveTime > this.keepaliveTime) { | ||
this.keepaliveTime = newKeepaliveTime; | ||
for (const wrappedSubchannel of this.wrappedSubchannels) { | ||
wrappedSubchannel.throttleKeepalive(newKeepaliveTime); | ||
} | ||
} | ||
} | ||
removeWrappedSubchannel(wrappedSubchannel: ChannelSubchannelWrapper) { | ||
this.wrappedSubchannels.delete(wrappedSubchannel); | ||
} | ||
doPick(metadata: Metadata, extraPickInfo: {[key: string]: string}) { | ||
@@ -479,3 +526,3 @@ return this.currentPicker.pick({metadata: metadata, extraPickInfo: extraPickInfo}); | ||
'", deadline=' + | ||
deadline | ||
deadlineToString(deadline) | ||
); | ||
@@ -482,0 +529,0 @@ const finalOptions: CallStreamOptions = { |
@@ -208,7 +208,7 @@ /* | ||
this.childSubchannelState = childSubchannel.getConnectivityState(); | ||
childSubchannel.addConnectivityStateListener((subchannel, previousState, newState) => { | ||
childSubchannel.addConnectivityStateListener((subchannel, previousState, newState, keepaliveTime) => { | ||
this.childSubchannelState = newState; | ||
if (!this.ejected) { | ||
for (const listener of this.stateListeners) { | ||
listener(this, previousState, newState); | ||
listener(this, previousState, newState, keepaliveTime); | ||
} | ||
@@ -269,3 +269,3 @@ } | ||
for (const listener of this.stateListeners) { | ||
listener(this, this.childSubchannelState, ConnectivityState.TRANSIENT_FAILURE); | ||
listener(this, this.childSubchannelState, ConnectivityState.TRANSIENT_FAILURE, -1); | ||
} | ||
@@ -277,3 +277,3 @@ } | ||
for (const listener of this.stateListeners) { | ||
listener(this, ConnectivityState.TRANSIENT_FAILURE, this.childSubchannelState); | ||
listener(this, ConnectivityState.TRANSIENT_FAILURE, this.childSubchannelState, -1); | ||
} | ||
@@ -280,0 +280,0 @@ } |
@@ -21,3 +21,3 @@ /* | ||
import { LogVerbosity, Propagate, Status } from "./constants"; | ||
import { Deadline, getDeadlineTimeoutString, getRelativeTimeout, minDeadline } from "./deadline"; | ||
import { Deadline, deadlineToString, getDeadlineTimeoutString, getRelativeTimeout, minDeadline } from "./deadline"; | ||
import { FilterStack, FilterStackFactory } from "./filter-stack"; | ||
@@ -83,5 +83,5 @@ import { InternalChannel } from "./internal-channel"; | ||
clearTimeout(this.deadlineTimer); | ||
this.trace('Deadline: ' + this.deadline); | ||
if (this.deadline !== Infinity) { | ||
const timeout = getRelativeTimeout(this.deadline); | ||
this.trace('Deadline: ' + deadlineToString(this.deadline)); | ||
const timeout = getRelativeTimeout(this.deadline); | ||
if (timeout !== Infinity) { | ||
this.trace('Deadline will be reached in ' + timeout + 'ms'); | ||
@@ -88,0 +88,0 @@ const handleDeadline = () => { |
@@ -25,3 +25,4 @@ /* | ||
previousState: ConnectivityState, | ||
newState: ConnectivityState | ||
newState: ConnectivityState, | ||
keepaliveTime: number | ||
) => void; | ||
@@ -44,2 +45,3 @@ | ||
getAddress(): string; | ||
throttleKeepalive(newKeepaliveTime: number): void; | ||
ref(): void; | ||
@@ -72,2 +74,5 @@ unref(): void; | ||
} | ||
throttleKeepalive(newKeepaliveTime: number): void { | ||
this.child.throttleKeepalive(newKeepaliveTime); | ||
} | ||
ref(): void { | ||
@@ -74,0 +79,0 @@ this.child.ref(); |
@@ -67,3 +67,3 @@ /* | ||
private keepaliveTimeMultiplier = 1; | ||
private keepaliveTime: number; | ||
/** | ||
@@ -115,2 +115,4 @@ * Tracks channels and subchannel pools with references to this subchannel | ||
this.keepaliveTime = options['grpc.keepalive_time_ms'] ?? -1; | ||
if (options['grpc.enable_channelz'] === 0) { | ||
@@ -174,3 +176,3 @@ this.channelzEnabled = false; | ||
if (options['grpc.keepalive_time_ms']) { | ||
const adjustedKeepaliveTime = Math.min(options['grpc.keepalive_time_ms'] * this.keepaliveTimeMultiplier, KEEPALIVE_MAX_TIME_MS); | ||
const adjustedKeepaliveTime = Math.min(this.keepaliveTime, KEEPALIVE_MAX_TIME_MS); | ||
options = {...options, 'grpc.keepalive_time_ms': adjustedKeepaliveTime}; | ||
@@ -187,4 +189,4 @@ } | ||
this.transitionToState([ConnectivityState.READY], ConnectivityState.IDLE); | ||
if (tooManyPings) { | ||
this.keepaliveTimeMultiplier *= 2; | ||
if (tooManyPings && this.keepaliveTime > 0) { | ||
this.keepaliveTime *= 2; | ||
logging.log( | ||
@@ -194,4 +196,4 @@ LogVerbosity.ERROR, | ||
this.subchannelAddressString | ||
} rejected by server because of excess pings. Increasing ping interval multiplier to ${ | ||
this.keepaliveTimeMultiplier | ||
} rejected by server because of excess pings. Increasing ping interval to ${ | ||
this.keepaliveTime | ||
} ms` | ||
@@ -270,3 +272,3 @@ ); | ||
for (const listener of [...this.stateListeners]) { | ||
listener(this, previousState, newState); | ||
listener(this, previousState, newState, this.keepaliveTime); | ||
} | ||
@@ -412,2 +414,8 @@ return true; | ||
} | ||
throttleKeepalive(newKeepaliveTime: number) { | ||
if (newKeepaliveTime > this.keepaliveTime) { | ||
this.keepaliveTime = newKeepaliveTime; | ||
} | ||
} | ||
} |
@@ -80,3 +80,3 @@ /* | ||
*/ | ||
private keepaliveTimeMs: number = KEEPALIVE_MAX_TIME_MS; | ||
private keepaliveTimeMs: number = -1; | ||
/** | ||
@@ -137,3 +137,3 @@ * The amount of time to wait for an acknowledgement after sending a ping | ||
.join(' '); // remove falsey values first | ||
if ('grpc.keepalive_time_ms' in options) { | ||
@@ -339,2 +339,5 @@ this.keepaliveTimeMs = options['grpc.keepalive_time_ms']!; | ||
private startKeepalivePings() { | ||
if (this.keepaliveTimeMs < 0) { | ||
return; | ||
} | ||
this.keepaliveIntervalId = setInterval(() => { | ||
@@ -341,0 +344,0 @@ this.sendPing(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1694586
445
33584
16