Skip to content

Commit d14228e

Browse files
committed
[gitpod-shared] Use "waitForSnapshot" to avoid disconnects
1 parent 022132f commit d14228e

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

extensions/gitpod-shared/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@types/ws": "^7.2.6"
1818
},
1919
"dependencies": {
20-
"@gitpod/gitpod-protocol": "akosyakov-code-new-gitpod-protocol-5717",
20+
"@gitpod/gitpod-protocol": "gpl-5862-snapshot",
2121
"@gitpod/supervisor-api-grpc": "ak-no-code-desktop-in-stable",
2222
"bufferutil": "^4.0.1",
2323
"reconnecting-websocket": "^4.4.0",

extensions/gitpod-shared/src/features.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require('reflect-metadata');
88
import { GitpodClient, GitpodServer, GitpodServiceImpl, WorkspaceInstanceUpdateListener } from '@gitpod/gitpod-protocol/lib/gitpod-service';
99
import { JsonRpcProxyFactory } from '@gitpod/gitpod-protocol/lib/messaging/proxy-factory';
1010
import { NavigatorContext, PullRequestContext, User } from '@gitpod/gitpod-protocol/lib/protocol';
11+
import { ErrorCodes } from '@gitpod/gitpod-protocol/lib/messaging/error';
1112
import { GitpodHostUrl } from '@gitpod/gitpod-protocol/lib/util/gitpod-host-url';
1213
import { ControlServiceClient } from '@gitpod/supervisor-api-grpc/lib/control_grpc_pb';
1314
import { InfoServiceClient } from '@gitpod/supervisor-api-grpc/lib/info_grpc_pb';
@@ -29,7 +30,7 @@ import ReconnectingWebSocket from 'reconnecting-websocket';
2930
import { URL } from 'url';
3031
import * as util from 'util';
3132
import * as vscode from 'vscode';
32-
import { ConsoleLogger, listen as doListen } from 'vscode-ws-jsonrpc';
33+
import { CancellationToken, ConsoleLogger, listen as doListen } from 'vscode-ws-jsonrpc';
3334
import WebSocket = require('ws');
3435
import { BaseGitpodAnalyticsEventPropeties, GitpodAnalyticsEvent } from './analytics';
3536
import * as uuid from 'uuid';
@@ -68,7 +69,7 @@ export class SupervisorConnection {
6869
}
6970
}
7071

71-
type UsedGitpodFunction = ['getWorkspace', 'openPort', 'stopWorkspace', 'setWorkspaceTimeout', 'getWorkspaceTimeout', 'getLoggedInUser', 'takeSnapshot', 'controlAdmission', 'sendHeartBeat', 'trackEvent'];
72+
type UsedGitpodFunction = ['getWorkspace', 'openPort', 'stopWorkspace', 'setWorkspaceTimeout', 'getWorkspaceTimeout', 'getLoggedInUser', 'takeSnapshot', 'waitForSnapshot', 'controlAdmission', 'sendHeartBeat', 'trackEvent'];
7273
type Union<Tuple extends any[], Union = never> = Tuple[number] | Union;
7374
export type GitpodConnection = Omit<GitpodServiceImpl<GitpodClient, GitpodServer>, 'server'> & {
7475
server: Pick<GitpodServer, Union<UsedGitpodFunction>>
@@ -237,7 +238,7 @@ export async function createGitpodExtensionContext(context: vscode.ExtensionCont
237238
const gitpodApi = workspaceInfo.getGitpodApi()!;
238239

239240
const factory = new JsonRpcProxyFactory<GitpodServer>();
240-
const gitpodFunctions: UsedGitpodFunction = ['getWorkspace', 'openPort', 'stopWorkspace', 'setWorkspaceTimeout', 'getWorkspaceTimeout', 'getLoggedInUser', 'takeSnapshot', 'controlAdmission', 'sendHeartBeat', 'trackEvent'];
241+
const gitpodFunctions: UsedGitpodFunction = ['getWorkspace', 'openPort', 'stopWorkspace', 'setWorkspaceTimeout', 'getWorkspaceTimeout', 'getLoggedInUser', 'takeSnapshot', 'waitForSnapshot', 'controlAdmission', 'sendHeartBeat', 'trackEvent'];
241242
const gitpodService: GitpodConnection = new GitpodServiceImpl<GitpodClient, GitpodServer>(factory.createProxy()) as any;
242243
const gitpodScopes = new Set<string>([
243244
'resource:workspace::' + workspaceId + '::get/update',
@@ -474,13 +475,33 @@ export async function registerWorkspaceCommands(context: GitpodExtensionContext)
474475
properties: { action: 'snapshot' }
475476
});
476477
try {
477-
const snapshotId = await vscode.window.withProgress({
478+
let snapshotId: string | undefined = undefined;
479+
await vscode.window.withProgress({
478480
location: vscode.ProgressLocation.Notification,
479481
cancellable: true,
480482
title: 'Capturing workspace snapshot'
481-
}, _ => {
482-
return context.gitpod.server.takeSnapshot({ workspaceId: context.info.getWorkspaceId() /*, layoutData?*/ });
483+
}, async (_, cancelToken: CancellationToken) => {
484+
snapshotId = await context.gitpod.server.takeSnapshot({ workspaceId: context.info.getWorkspaceId() /*, layoutData?*/, dontWait: true });
485+
486+
while (!cancelToken.isCancellationRequested) {
487+
try {
488+
await context.gitpod.server.waitForSnapshot(snapshotId);
489+
return;
490+
} catch (err) {
491+
if (err.code === ErrorCodes.SNAPSHOT_ERROR || err.code === ErrorCodes.NOT_FOUND) {
492+
// this is indeed an error with snapshot creation itself, break here!
493+
throw err;
494+
}
495+
496+
// other errors (like connection errors): retry
497+
await new Promise((resolve) => setTimeout(resolve, 3000));
498+
}
499+
}
483500
});
501+
if (!snapshotId) {
502+
throw new Error('error taking snapshot');
503+
}
504+
484505
const hostname = context.info.getGitpodApi()!.getHost();
485506
const uri = `https://${hostname}#snapshot/${snapshotId}`;
486507
const copyAction = await vscode.window.showInformationMessage(`The current state is captured in a snapshot. Using [this link](${uri}) anybody can create their own copy of this workspace.`,

extensions/yarn.lock

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22
# yarn lockfile v1
33

44

5-
"@gitpod/gitpod-protocol@akosyakov-code-new-gitpod-protocol-5717":
6-
version "0.1.5-akosyakov-code-new-gitpod-protocol-5717.0"
7-
resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-akosyakov-code-new-gitpod-protocol-5717.0.tgz#2ba3dbf8977a918617c43e057a632cf491a63a17"
8-
integrity sha512-/A4NU1YVa9ACnmQMxZTHoiSzbJvhl4yubFUot3HcptUnzSND4DUj3Se4m7hIRCT2GNtpbQyeTDJhdXwVxgrOrg==
5+
"@gitpod/gitpod-protocol@gpl-5862-snapshot":
6+
version "0.1.5-gpl-5862-snapshot.33"
7+
resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-gpl-5862-snapshot.33.tgz#fc08bbc24559464ce7d5bd445aefaf8d29f50e7e"
8+
integrity sha512-fhfCwZzOBmSM4UavpLkK3RsfPuw2U49q3eAGUKbMYGqnscEXjqLi1Z0QatFMOWGdybfTYeRghMqEm7XYBD5i4g==
99
dependencies:
1010
ajv "^6.5.4"
1111
analytics-node "^4.0.1"
12+
cookie "^0.4.1"
1213
inversify "^5.0.1"
1314
jaeger-client "3.17.2"
1415
js-yaml "^3.10.0"
1516
opentracing "^0.14.4"
16-
prom-client "^10.2.0"
17+
prom-client "^13.2.0"
1718
random-number-csprng "^1.0.2"
1819
reconnecting-websocket "^4.4.0"
1920
reflect-metadata "^0.1.10"
2021
uuid "^3.3.3"
22+
vscode-jsonrpc "^5.0.1"
23+
vscode-languageserver-protocol "3.15.3"
2124
vscode-uri "^1.0.1"
2225
vscode-ws-jsonrpc "^0.2.0"
2326
ws "^7.4.6"
@@ -266,6 +269,11 @@ [email protected]:
266269
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
267270
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
268271

272+
cookie@^0.4.1:
273+
version "0.4.1"
274+
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.1.tgz#afd713fe26ebd21ba95ceb61f9a8116e50a537d1"
275+
integrity sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==
276+
269277
create-error@^0.3.1:
270278
version "0.3.1"
271279
resolved "https://registry.yarnpkg.com/create-error/-/create-error-0.3.1.tgz#69810245a629e654432bf04377360003a5351a23"
@@ -542,10 +550,10 @@ process@^0.10.0:
542550
resolved "https://registry.yarnpkg.com/process/-/process-0.10.1.tgz#842457cc51cfed72dc775afeeafb8c6034372725"
543551
integrity sha1-hCRXzFHP7XLcd1r+6vuMYDQ3JyU=
544552

545-
prom-client@^10.2.0:
546-
version "10.2.3"
547-
resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-10.2.3.tgz#a51bf21c239c954a6c5be4b1361fdd380218bb41"
548-
integrity sha512-Xboq5+TdUwuQtSSDRZRNnb5NprINlgQN999VqUjZxnLKydUNLeIPx6Eiahg6oJua3XBg2TGnh5Cth1s4I6+r7g==
553+
prom-client@^13.2.0:
554+
version "13.2.0"
555+
resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-13.2.0.tgz#99d13357912dd400f8911b77df19f7b328a93e92"
556+
integrity sha512-wGr5mlNNdRNzEhRYXgboUU2LxHWIojxscJKmtG3R8f4/KiWqyYgXTLHs0+Ted7tG3zFT7pgHJbtomzZ1L0ARaQ==
549557
dependencies:
550558
tdigest "^0.1.1"
551559

@@ -669,6 +677,19 @@ vscode-jsonrpc@^5.0.0, vscode-jsonrpc@^5.0.1:
669677
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-5.0.1.tgz#9bab9c330d89f43fc8c1e8702b5c36e058a01794"
670678
integrity sha512-JvONPptw3GAQGXlVV2utDcHx0BiY34FupW/kI6mZ5x06ER5DdPG/tXWMVHjTNULF5uKPOUUD0SaXg5QaubJL0A==
671679

680+
681+
version "3.15.3"
682+
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.3.tgz#3fa9a0702d742cf7883cb6182a6212fcd0a1d8bb"
683+
integrity sha512-zrMuwHOAQRhjDSnflWdJG+O2ztMWss8GqUUB8dXLR/FPenwkiBNkMIJJYfSN6sgskvsF0rHAoBowNQfbyZnnvw==
684+
dependencies:
685+
vscode-jsonrpc "^5.0.1"
686+
vscode-languageserver-types "3.15.1"
687+
688+
689+
version "3.15.1"
690+
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz#17be71d78d2f6236d414f0001ce1ef4d23e6b6de"
691+
integrity sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ==
692+
672693
vscode-nls@^5.0.0:
673694
version "5.0.0"
674695
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.0.0.tgz#99f0da0bd9ea7cda44e565a74c54b1f2bc257840"

0 commit comments

Comments
 (0)