Skip to content

Commit

Permalink
Remove outdated conncheck retry workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihildt committed Nov 25, 2024
1 parent 020e41f commit c1540cd
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/helpers/connCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ import type {
Ipv4ServerResponse,
} from '@/helpers/connCheck.types';

/*
By default, it will retry twice because after connecting/disconnecting to/from Mullvad server, the first request results in a NetworkError and the second is successful.
export const connCheckIpv4 = async (): Promise<Connection> => {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 6000);

It's a workaround for the following bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1706377
Workaround can be removed when Mullvad Browser 14.0 is released (the bug is fixed!).
*/
const MAX_RETRIES = 3;

export const connCheckIpv4 = async (retries = MAX_RETRIES): Promise<Connection> => {
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 6000);

const response = await fetch('https://ipv4.am.i.mullvad.net/json', {
method: 'GET',
headers: {
Expand All @@ -38,12 +30,11 @@ export const connCheckIpv4 = async (retries = MAX_RETRIES): Promise<Connection>
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
if (retries === 1) throw new Error('IPv4 connection check failed.');
return connCheckIpv4(retries - 1);
throw new Error('IPv4 connection check failed.');
}
};

export const connCheckIpv6 = async (retries = MAX_RETRIES): Promise<string | undefined> => {
export const connCheckIpv6 = async (): Promise<string | undefined> => {
try {
const response = await fetch('https://ipv6.am.i.mullvad.net/json', {
method: 'GET',
Expand All @@ -57,7 +48,6 @@ export const connCheckIpv6 = async (retries = MAX_RETRIES): Promise<string | und
if (__DEV__) {
console.log(`[conCheck IPv6]: Error trying to get ipv6 data: ${(e as Error).message}`);
}
if (retries === 1) return undefined;
return connCheckIpv6(retries - 1);
return undefined;
}
};

0 comments on commit c1540cd

Please sign in to comment.