Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added generate increment request id on retry #1347

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/ui/libs/DatalensChartkit/modules/axios/axios.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {AxiosError} from 'axios';
import type {AxiosError, AxiosRequestConfig} from 'axios';
import axios from 'axios';
import axiosRetry, {isRetryableError} from 'axios-retry';
import isNumber from 'lodash/isNumber';
import {REQUEST_ID_HEADER} from 'shared';
import {sleep} from 'shared/modules';
import {showReadOnlyToast} from 'ui/utils/readOnly';

Expand All @@ -17,6 +18,22 @@ const client = axios.create({
xsrfCookieName: '',
});

export const axiosOnRetryHandler = (
retryCount: number,
_: AxiosError,
requestConfig: AxiosRequestConfig,
) => {
if (requestConfig?.headers?.[REQUEST_ID_HEADER]) {
let requestId = requestConfig.headers[REQUEST_ID_HEADER];

if (retryCount > 1) {
requestId = requestId.slice(0, requestId.lastIndexOf('.'));
}

requestConfig.headers[REQUEST_ID_HEADER] = `${requestId}.${retryCount}`;
}
};

initConcurrencyManager(Infinity);

export function initConcurrencyManager(maxConcurrentRequests: number) {
Expand Down Expand Up @@ -45,6 +62,7 @@ export function initConcurrencyManager(maxConcurrentRequests: number) {
retries: 0,
retryCondition: isRetryableError,
retryDelay: () => 3000,
onRetry: axiosOnRetryHandler,
});

// it is necessary to store the indexes of the positions of the interceptors added by axios-retry, to bring ability to delete them
Expand Down
Loading