summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls <emils@mullvad.net>2020-08-19 11:44:52 +0100
committerDavid Lönnhager <david.l@mullvad.net>2020-08-20 14:41:42 +0200
commitf30f2c84e6ebcceed3408358c8df4a2239c0de71 (patch)
tree0fd01b6bc4aefd1a5ad744714ea723132cccef4f
parentd0fcbfaaebb69db037dc63cb41c6eb3dc58aa49b (diff)
downloadmullvadvpn-f30f2c84e6ebcceed3408358c8df4a2239c0de71.tar.xz
mullvadvpn-f30f2c84e6ebcceed3408358c8df4a2239c0de71.zip
Handle shutdown of GRPC connection gracefully
-rw-r--r--gui/src/main/daemon-rpc.ts18
-rw-r--r--gui/src/main/index.ts2
2 files changed, 16 insertions, 4 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts
index a86fcbbac2..64930c734c 100644
--- a/gui/src/main/daemon-rpc.ts
+++ b/gui/src/main/daemon-rpc.ts
@@ -238,11 +238,12 @@ export class DaemonRpc {
log.error(`Failed to reconnect - ${error}`);
}),
);
- } else if (!wasConnected) {
+ this.setChannelCallback(currentState);
+ } else if (!wasConnected && currentState == grpc.connectivityState.READY) {
this.isConnected = true;
this.connectionObservers.forEach((observer) => observer.onOpen());
+ this.setChannelCallback(currentState);
}
- this.setChannelCallback(currentState);
}
}
@@ -550,12 +551,21 @@ export class DaemonRpc {
const removeSubscription = () => {
const subscription = this.subscriptions.get(subscriptionId);
if (subscription !== undefined) {
- subscription.cancel();
this.subscriptions.delete(subscriptionId);
+ subscription.cancel();
}
};
call.on('error', (error) => {
+ // if the subscription was cancelled by the client, there's no reason to
+ // invoke the onError handler
+ if (
+ 'code' in error &&
+ error['code'] == grpc.status.CANCELLED &&
+ !this.subscriptions.has(subscriptionId)
+ ) {
+ return;
+ }
listener.onError(error);
removeSubscription();
});
@@ -566,8 +576,8 @@ export class DaemonRpc {
if (id !== undefined) {
const subscription = this.subscriptions.get(id);
if (subscription !== undefined) {
- subscription.cancel();
this.subscriptions.delete(id);
+ subscription.cancel();
}
}
}
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index 37394d0276..3ad81f453d 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -320,6 +320,8 @@ class ApplicationMain {
if (process.platform === 'darwin' && this.windowController) {
this.windowController.window.closable = true;
}
+
+ this.daemonRpc.disconnect();
}
private detectLocale(): string {