diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-11-12 11:29:21 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-11-13 14:31:44 +0100 |
| commit | d27b92c5a613a45acf6b950ac32ee3b83abc08a2 (patch) | |
| tree | a973e021f679f053688579cbecd88d402601c0c6 /gui | |
| parent | 6308f657a0e766ae22001889a21ef600e2c0bd75 (diff) | |
| download | mullvadvpn-d27b92c5a613a45acf6b950ac32ee3b83abc08a2.tar.xz mullvadvpn-d27b92c5a613a45acf6b950ac32ee3b83abc08a2.zip | |
Fix race condition in updateLocation
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/src/main/index.ts | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 33027f32e3..95cfc35a55 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -142,6 +142,7 @@ class ApplicationMain { private location?: ILocation; private lastDisconnectedLocation?: ILocation; private tunnelStateExpectation?: Expectation; + private getLocationPromise?: Promise<ILocation>; private relays: IRelayList = { countries: [] }; @@ -846,7 +847,8 @@ class ApplicationMain { if (tunnelState.state === 'connected' || tunnelState.state === 'disconnected') { try { // Fetch the new user location - const location = await this.daemonRpc.getLocation(); + const getLocationPromise = (this.getLocationPromise = this.daemonRpc.getLocation()); + const location = await getLocationPromise; // If the location is currently unavailable, do nothing! This only ever // happens when a custom relay is set or we are in a blocked state. if (!location) { @@ -859,10 +861,8 @@ class ApplicationMain { this.lastDisconnectedLocation = location; } - // Broadcast the new location. - // There is a chance that the location is not stale if the tunnel state before the location - // request is the same as after receiving the response. - if (this.tunnelState.state === tunnelState.state) { + // Broadcast the new location if it is the result of the most recent call to getLocation. + if (getLocationPromise === this.getLocationPromise) { this.setLocation(location); } } catch (error) { |
