fix: make fileserver request retry

pull/2940/head
Audric Ackermann 1 year ago
parent a203ea79cd
commit 2c479eb8d5

@ -191,7 +191,7 @@
"confirm": "Confirm", "confirm": "Confirm",
"followSetting": "Follow Setting", "followSetting": "Follow Setting",
"followSettingDisabled": "Messages you send will no longer disappear. Are you sure you want to turn off disappearing messages?", "followSettingDisabled": "Messages you send will no longer disappear. Are you sure you want to turn off disappearing messages?",
"followSettingTimeAndType": "Set your messages to disappear $time$ after they have been $type$?", "followSettingTimeAndType": "Set your messages to disappear <b>$time$</b> after they have been <b>$type$</b>?",
"youChangedTheTimer": "<b>You</b> have set messages to disappear <b>$time$</b> after they have been <b>$mode$</b>", "youChangedTheTimer": "<b>You</b> have set messages to disappear <b>$time$</b> after they have been <b>$mode$</b>",
"youChangedTheTimerLegacy": "<b>You</b> set the disappearing message timer to <b>$time$</b>", "youChangedTheTimerLegacy": "<b>You</b> set the disappearing message timer to <b>$time$</b>",
"theyChangedTheTimer": "<b>$name$</b> has set messages to disappear <b>$time$</b> after they have been <b>$mode$</b>", "theyChangedTheTimer": "<b>$name$</b> has set messages to disappear <b>$time$</b> after they have been <b>$mode$</b>",

@ -756,6 +756,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
* Also returns the uploaded ids to include in the message post so that those attachments are linked to that message. * Also returns the uploaded ids to include in the message post so that those attachments are linked to that message.
*/ */
public async uploadData() { public async uploadData() {
const start = Date.now();
const finalAttachments = await Promise.all( const finalAttachments = await Promise.all(
(this.get('attachments') || []).map(loadAttachmentData) (this.get('attachments') || []).map(loadAttachmentData)
); );
@ -816,7 +817,10 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
attachments[0].flags = SignalService.AttachmentPointer.Flags.VOICE_MESSAGE; attachments[0].flags = SignalService.AttachmentPointer.Flags.VOICE_MESSAGE;
} }
window.log.info(`Upload of message data for message ${this.idForLogging()} is finished.`); window.log.info(
`Upload of message data for message ${this.idForLogging()} is finished in ${Date.now() -
start}ms.`
);
return { return {
body, body,
attachments, attachments,

@ -5,7 +5,9 @@ import {
parseBatchGlobalStatusCode, parseBatchGlobalStatusCode,
} from '../open_group_api/sogsv3/sogsV3BatchPoll'; } from '../open_group_api/sogsv3/sogsV3BatchPoll';
export const fileServerURL = 'http://filev2.getsession.org'; export const fileServerHost = 'filev2.getsession.org';
export const fileServerURL = `http://${fileServerHost}`;
export const fileServerPubKey = 'da21e1d886c6fbaea313f75298bd64aab03a97ce985b46bb2dad9f2089c8ee59'; export const fileServerPubKey = 'da21e1d886c6fbaea313f75298bd64aab03a97ce985b46bb2dad9f2089c8ee59';
const RELEASE_VERSION_ENDPOINT = '/session_version?platform=desktop'; const RELEASE_VERSION_ENDPOINT = '/session_version?platform=desktop';

@ -1,25 +1,26 @@
import https from 'https'; import https from 'https';
// eslint-disable-next-line import/no-named-default // eslint-disable-next-line import/no-named-default
import { default as insecureNodeFetch, RequestInit, Response } from 'node-fetch';
import ByteBuffer from 'bytebuffer';
import pRetry from 'p-retry';
import { cloneDeep, isEmpty, isString, omit } from 'lodash';
import { AbortSignal } from 'abort-controller'; import { AbortSignal } from 'abort-controller';
import ByteBuffer from 'bytebuffer';
import { to_string } from 'libsodium-wrappers-sumo'; import { to_string } from 'libsodium-wrappers-sumo';
import { cloneDeep, isEmpty, isString, omit } from 'lodash';
import { RequestInit, Response, default as insecureNodeFetch } from 'node-fetch';
import pRetry from 'p-retry';
// eslint-disable-next-line import/no-unresolved // eslint-disable-next-line import/no-unresolved
import { AbortSignal as AbortSignalNode } from 'node-fetch/externals'; import { AbortSignal as AbortSignalNode } from 'node-fetch/externals';
import { dropSnodeFromSnodePool, dropSnodeFromSwarmIfNeeded, updateSwarmFor } from './snodePool'; import { dropSnodeFromSnodePool, dropSnodeFromSwarmIfNeeded, updateSwarmFor } from './snodePool';
import { OnionPaths } from '../../onions'; import { OnionPaths } from '../../onions';
import { toHex } from '../../utils/String';
import { ed25519Str, incrementBadPathCountOrDrop } from '../../onions/onionPath'; import { ed25519Str, incrementBadPathCountOrDrop } from '../../onions/onionPath';
import { toHex } from '../../utils/String';
import { Snode } from '../../../data/data'; import { Snode } from '../../../data/data';
import { ERROR_CODE_NO_CONNECT } from './SNodeAPI';
import { hrefPnServerProd } from '../push_notification_api/PnServer';
import { callUtilsWorker } from '../../../webworker/workers/browser/util_worker_interface'; import { callUtilsWorker } from '../../../webworker/workers/browser/util_worker_interface';
import { encodeV4Request } from '../../onions/onionv4'; import { encodeV4Request } from '../../onions/onionv4';
import { fileServerHost } from '../file_server_api/FileServerApi';
import { hrefPnServerProd } from '../push_notification_api/PnServer';
import { ERROR_CODE_NO_CONNECT } from './SNodeAPI';
// hold the ed25519 key of a snode against the time it fails. Used to remove a snode only after a few failures (snodeFailureThreshold failures) // hold the ed25519 key of a snode against the time it fails. Used to remove a snode only after a few failures (snodeFailureThreshold failures)
let snodeFailureCount: Record<string, number> = {}; let snodeFailureCount: Record<string, number> = {};
@ -839,6 +840,7 @@ async function sendOnionRequestHandlingSnodeEject({
response = result.response; response = result.response;
if ( if (
!isEmpty(finalRelayOptions) && !isEmpty(finalRelayOptions) &&
finalRelayOptions.host !== fileServerHost &&
response.status === 502 && response.status === 502 &&
response.statusText === 'Bad Gateway' response.statusText === 'Bad Gateway'
) { ) {
@ -848,6 +850,7 @@ async function sendOnionRequestHandlingSnodeEject({
decodingSymmetricKey = result.decodingSymmetricKey; decodingSymmetricKey = result.decodingSymmetricKey;
} catch (e) { } catch (e) {
window?.log?.warn('sendOnionRequestNoRetries error message: ', e.message); window?.log?.warn('sendOnionRequestNoRetries error message: ', e.message);
if (e.code === 'ENETUNREACH' || e.message === 'ENETUNREACH' || throwErrors) { if (e.code === 'ENETUNREACH' || e.message === 'ENETUNREACH' || throwErrors) {
throw e; throw e;
} }

@ -1,27 +1,27 @@
import { AbortSignal } from 'abort-controller';
import { toNumber } from 'lodash'; import { toNumber } from 'lodash';
import pRetry from 'p-retry'; import pRetry from 'p-retry';
import { AbortSignal } from 'abort-controller';
import { OnionPaths } from '.'; import { OnionPaths } from '.';
import { Snode } from '../../data/data';
import { fileServerPubKey, fileServerURL } from '../apis/file_server_api/FileServerApi';
import { OpenGroupPollingUtils } from '../apis/open_group_api/opengroupV2/OpenGroupPollingUtils';
import { invalidAuthRequiresBlinding } from '../apis/open_group_api/opengroupV2/OpenGroupServerPoller';
import {
addBinaryContentTypeToHeaders,
addJsonContentTypeToHeaders,
} from '../apis/open_group_api/sogsv3/sogsV3SendMessage';
import { pnServerPubkeyHex, pnServerUrl } from '../apis/push_notification_api/PnServer';
import { import {
buildErrorMessageWithFailedCode,
FinalDestNonSnodeOptions, FinalDestNonSnodeOptions,
FinalRelayOptions, FinalRelayOptions,
Onions, Onions,
SnodeResponse,
STATUS_NO_STATUS, STATUS_NO_STATUS,
SnodeResponse,
buildErrorMessageWithFailedCode,
} from '../apis/snode_api/onions'; } from '../apis/snode_api/onions';
import { PROTOCOLS } from '../constants'; import { PROTOCOLS } from '../constants';
import { Snode } from '../../data/data';
import { OnionV4 } from './onionv4'; import { OnionV4 } from './onionv4';
import { OpenGroupPollingUtils } from '../apis/open_group_api/opengroupV2/OpenGroupPollingUtils';
import {
addBinaryContentTypeToHeaders,
addJsonContentTypeToHeaders,
} from '../apis/open_group_api/sogsv3/sogsV3SendMessage';
import { pnServerPubkeyHex, pnServerUrl } from '../apis/push_notification_api/PnServer';
import { fileServerPubKey, fileServerURL } from '../apis/file_server_api/FileServerApi';
import { invalidAuthRequiresBlinding } from '../apis/open_group_api/opengroupV2/OpenGroupServerPoller';
export type OnionFetchOptions = { export type OnionFetchOptions = {
method: string; method: string;
@ -239,13 +239,13 @@ const sendViaOnionV4ToNonSnodeWithRetries = async (
minTimeout: 100, minTimeout: 100,
onFailedAttempt: e => { onFailedAttempt: e => {
window?.log?.warn( window?.log?.warn(
`sendViaOnionV4ToNonSnodeRetryable attempt #${e.attemptNumber} failed. ${e.retriesLeft} retries left...: ${e.message}` `sendViaOnionV4ToNonSnodeWithRetries attempt #${e.attemptNumber} failed. ${e.retriesLeft} retries left...: ${e.message}`
); );
}, },
} }
); );
} catch (e) { } catch (e) {
window?.log?.warn('sendViaOnionV4ToNonSnodeRetryable failed ', e.message, throwErrors); window?.log?.warn('sendViaOnionV4ToNonSnodeWithRetries failed ', e.message, throwErrors);
if (throwErrors) { if (throwErrors) {
throw e; throw e;
} }

Loading…
Cancel
Save