提交 29e6dce4 编写于 作者: A Alex Dima

Fixes #58672: Accomodate for never completed requests

上级 87dbb3a1
......@@ -123,7 +123,7 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
private readonly _cancelInvokedHandlers: { [req: string]: () => void; };
private readonly _pendingRPCReplies: { [msgId: string]: LazyPromise; };
private _responsiveState: ResponsiveState;
private _pendingRPCRepliesCount: number;
private _potentialUnresponsiveRequests: number[];
private _unresponsiveTime: number;
private _asyncCheckUresponsive: RunOnceScheduler;
......@@ -143,7 +143,7 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
this._cancelInvokedHandlers = Object.create(null);
this._pendingRPCReplies = {};
this._responsiveState = ResponsiveState.Responsive;
this._pendingRPCRepliesCount = 0;
this._potentialUnresponsiveRequests = [];
this._unresponsiveTime = 0;
this._asyncCheckUresponsive = this._register(new RunOnceScheduler(() => this._checkUnresponsive(), 1000));
this._protocol.onMessage((msg) => this._receiveOneMessage(msg));
......@@ -159,23 +159,26 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
});
}
private _onWillSendRequest(): void {
if (this._pendingRPCRepliesCount === 0) {
private _onWillSendRequest(req: number): void {
if (this._potentialUnresponsiveRequests.length === 0) {
// Since this is the first request we are sending in a while,
// mark this moment as the start for the countdown to unresponsive time
this._unresponsiveTime = Date.now() + RPCProtocol.UNRESPONSIVE_TIME;
}
this._pendingRPCRepliesCount++;
this._potentialUnresponsiveRequests.push(req);
if (!this._asyncCheckUresponsive.isScheduled()) {
this._asyncCheckUresponsive.schedule();
}
}
private _onWillReceiveReply(): void {
private _onWillReceiveReply(req: number): void {
// The next possible unresponsive time is now + delta.
this._unresponsiveTime = Date.now() + RPCProtocol.UNRESPONSIVE_TIME;
this._pendingRPCRepliesCount--;
if (this._pendingRPCRepliesCount === 0) {
// Remove all previous requests from the potential unresponsive list
while (this._potentialUnresponsiveRequests.length > 0 && this._potentialUnresponsiveRequests[0] <= req) {
this._potentialUnresponsiveRequests.shift();
}
if (this._potentialUnresponsiveRequests.length === 0) {
// No more need to check for unresponsive
this._asyncCheckUresponsive.cancel();
}
......@@ -184,7 +187,7 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
}
private _checkUnresponsive(): void {
if (this._pendingRPCRepliesCount === 0) {
if (this._potentialUnresponsiveRequests.length === 0) {
// Not waiting for anything => cannot say if it is responsive or not
return;
}
......@@ -194,7 +197,7 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
this._setResponsiveState(ResponsiveState.Unresponsive);
} else {
// Not (yet) unresponsive, be sure to check again soon
if (this._pendingRPCRepliesCount > 0) {
if (this._potentialUnresponsiveRequests.length > 0) {
this._asyncCheckUresponsive.schedule();
}
}
......@@ -383,7 +386,7 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
const pendingReply = this._pendingRPCReplies[callId];
delete this._pendingRPCReplies[callId];
this._onWillReceiveReply();
this._onWillReceiveReply(req);
pendingReply.resolveOk(value);
}
......@@ -400,7 +403,7 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
const pendingReply = this._pendingRPCReplies[callId];
delete this._pendingRPCReplies[callId];
this._onWillReceiveReply();
this._onWillReceiveReply(req);
let err: Error = null;
if (value && value.$isError) {
......@@ -461,7 +464,7 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
}
this._pendingRPCReplies[callId] = result;
this._onWillSendRequest();
this._onWillSendRequest(req);
if (this._uriTransformer) {
args = transformOutgoingURIs(args, this._uriTransformer);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册