Skip to content

Commit

Permalink
[Main][BUG] remove 403 as a “retriable” error code #2296 (#2298)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Mar 12, 2024
1 parent 1c3db30 commit 02a003b
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 175 deletions.
4 changes: 2 additions & 2 deletions AISKULight/Tests/Unit/src/AISKULightSize.Tests.ts
Expand Up @@ -4,8 +4,8 @@ import * as pako from "pako";
export class AISKULightSizeCheck extends AITestClass {
private readonly MAX_RAW_SIZE = 86;
private readonly MAX_BUNDLE_SIZE = 86;
private readonly MAX_RAW_DEFLATE_SIZE = 35;
private readonly MAX_BUNDLE_DEFLATE_SIZE = 35;
private readonly MAX_RAW_DEFLATE_SIZE = 36;
private readonly MAX_BUNDLE_DEFLATE_SIZE = 36;
private readonly rawFilePath = "../dist/es5/applicationinsights-web-basic.min.js";
private readonly currentVer = "3.1.0";
private readonly prodFilePath = `../browser/es5/aib.${this.currentVer[0]}.min.js`;
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -394,6 +394,7 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| storagePrefix | string[] | undefined | [Optional] An optional value that will be added as name prefix for storage name. |
| featureOptIn <br/><sub>since 3.0.3</sub> | IFeatureOptIn | undefined | [Optional] Set Feature opt in details. |
| throttleMgrCfg <br/><sub>since 3.0.3</sub> | `{[key: number]: IThrottleMgrConfig}` | undefined | [Optional] Set throttle mgr configuration by key. |
| retryCodes | number[] | undefined | Identifies the status codes that will cause event batches to be resent, when `null` or `undefined` the SDK will use it's defaults `[401, 408, 429, 500, 502, 503, 504]`. `403` was removed in version 3.1.1. |

### ICookieMgrConfig

Expand Down
10 changes: 7 additions & 3 deletions channels/applicationinsights-channel-js/src/Interfaces.ts
Expand Up @@ -127,16 +127,20 @@ export interface ISenderConfig {
* [Optional] Either an array or single value identifying the requested TransportType type that should be used.
* This is used during initialization to identify the requested send transport, it will be ignored if a httpXHROverride is provided.
*/
transports?: number | number[];
transports?: number | number[];

/**
* [Optional] Either an array or single value identifying the requested TransportType type(s) that should be used during unload or events
* marked as sendBeacon. This is used during initialization to identify the requested send transport, it will be ignored if a httpXHROverride
* is provided and alwaysUseXhrOverride is true.
*/
unloadTransports?: number | number[];
unloadTransports?: number | number[];


/**
* (Optional) The specific error codes that will cause a retry of sending data to the backend.
* @since 3.1.1
*/
retryCodes?: number[];
}

export interface IBackendResponse {
Expand Down
13 changes: 11 additions & 2 deletions channels/applicationinsights-channel-js/src/Sender.ts
Expand Up @@ -72,7 +72,8 @@ const defaultAppInsightsChannelConfig: IConfigDefaults<ISenderConfig> = objDeepF
bufferOverride: false,
httpXHROverride: { isVal: isOverrideFn, v:UNDEFINED_VALUE },
alwaysUseXhrOverride: cfgDfBoolean(),
transports: UNDEFINED_VALUE
transports: UNDEFINED_VALUE,
retryCodes: UNDEFINED_VALUE
});

function _chkSampling(value: number) {
Expand Down Expand Up @@ -176,6 +177,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
let _fallbackSend: SenderFunction;
let _disableBeaconSplit: boolean;
let _sendPostMgr: SenderPostManager;
let _retryCodes: number[];

dynamicProto(Sender, this, (_self, _base) => {

Expand Down Expand Up @@ -289,6 +291,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {

_alwaysUseCustomSend = senderConfig.alwaysUseXhrOverride;
_disableXhr = !!senderConfig.disableXhr;
_retryCodes = senderConfig.retryCodes;

let bufferOverride = senderConfig.bufferOverride;
let canUseSessionStorage = !!senderConfig.enableSessionStorageBuffer &&
Expand Down Expand Up @@ -1116,8 +1119,14 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
* @param statusCode
*/
function _isRetriable(statusCode: number): boolean {
// retryCodes = [] means should not retry
if (!isNullOrUndefined(_retryCodes)) {
return _retryCodes.length && _retryCodes.indexOf(statusCode) > -1;
}

return statusCode === 401 // Unauthorized
|| statusCode === 403 // Forbidden
// Removing as private links can return a 403 which causes excessive retries and session storage usage
// || statusCode === 403 // Forbidden
|| statusCode === 408 // Timeout
|| statusCode === 429 // Too many requests.
|| statusCode === 500 // Internal server error.
Expand Down
3 changes: 1 addition & 2 deletions channels/offline-channel-js/src/OfflineBatchHandler.ts
Expand Up @@ -29,7 +29,6 @@ export class OfflineBatchHandler implements IOfflineBatchHandler {
let _maxRetryCnt: number;
let _retryCodes: number[];


_initDefaults();

_self.initialize = (providerContext: ILocalStorageProviderContext) => {
Expand Down Expand Up @@ -350,8 +349,8 @@ export class OfflineBatchHandler implements IOfflineBatchHandler {
// retryCodes = [] means should not retry
if (!isNullOrUndefined(_retryCodes)) {
return _retryCodes.length && _retryCodes.indexOf(statusCode) > -1;

}

return statusCode === 401 // Unauthorized
|| statusCode === 403 // Forbidden
|| statusCode === 408 // Timeout
Expand Down

0 comments on commit 02a003b

Please sign in to comment.