Set 5s as default timeout for ping (#6271)

This commit is contained in:
Elias Nahum
2022-05-13 11:36:30 -04:00
committed by GitHub
parent e81e98aa02
commit 2c6bd00128
4 changed files with 11 additions and 5 deletions

View File

@@ -35,7 +35,8 @@ async function getDeviceIdForPing(serverUrl: string, checkDeviceId: boolean) {
return getDeviceToken(appDatabase);
}
export const doPing = async (serverUrl: string, verifyPushProxy: boolean) => {
// Default timeout interval for ping is 5 seconds
export const doPing = async (serverUrl: string, verifyPushProxy: boolean, timeoutInterval = 5) => {
let client: Client;
try {
client = await NetworkManager.createClient(serverUrl);
@@ -57,7 +58,7 @@ export const doPing = async (serverUrl: string, verifyPushProxy: boolean) => {
let response: ClientResponse;
try {
response = await client.ping(deviceId);
response = await client.ping(deviceId, timeoutInterval);
if (response.code === 401) {
// Don't invalidate the client since we want to eventually

View File

@@ -244,6 +244,10 @@ export default class ClientBase {
retryLimit: 0,
};
}
if (options.timeoutInterval) {
requestOptions.timeoutInterval = options.timeoutInterval;
}
let response: ClientResponse;
try {
response = await request!(url, requestOptions);

View File

@@ -7,7 +7,7 @@ import ClientError from './error';
export interface ClientGeneralMix {
getOpenGraphMetadata: (url: string) => Promise<any>;
ping: (deviceId?: string) => Promise<any>;
ping: (deviceId?: string, timeoutInterval?: number) => Promise<any>;
logClientError: (message: string, level?: string) => Promise<any>;
getClientConfigOld: () => Promise<ClientConfig>;
getClientLicenseOld: () => Promise<ClientLicense>;
@@ -25,14 +25,14 @@ const ClientGeneral = (superclass: any) => class extends superclass {
);
};
ping = async (deviceId?: string) => {
ping = async (deviceId?: string, timeoutInterval?: number) => {
let url = `${this.urlVersion}/system/ping?time=${Date.now()}`;
if (deviceId) {
url = `${url}&device_id=${deviceId}`;
}
return this.doFetch(
url,
{method: 'get'},
{method: 'get', timeoutInterval},
false,
);
};

View File

@@ -7,6 +7,7 @@ type ClientOptions = {
body?: any;
method?: string;
noRetry?: boolean;
timeoutInterval?: number;
};
interface ClientErrorProps extends Error {