@azure/storage-file-share 12.28.0-alpha.20250617.1 → 12.28.0-alpha.20250717.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/dist/browser/AccountSASSignatureValues.d.ts +1 -1
  2. package/dist/browser/AccountSASSignatureValues.d.ts.map +1 -1
  3. package/dist/browser/AccountSASSignatureValues.js.map +1 -1
  4. package/dist/browser/Clients.d.ts +1 -1
  5. package/dist/browser/Clients.d.ts.map +1 -1
  6. package/dist/browser/Clients.js +3 -3
  7. package/dist/browser/Clients.js.map +1 -1
  8. package/dist/browser/FileSASSignatureValues.d.ts +1 -1
  9. package/dist/browser/FileSASSignatureValues.d.ts.map +1 -1
  10. package/dist/browser/FileSASSignatureValues.js.map +1 -1
  11. package/dist/browser/Pipeline.d.ts +2 -4
  12. package/dist/browser/Pipeline.d.ts.map +1 -1
  13. package/dist/browser/Pipeline.js +1 -9
  14. package/dist/browser/Pipeline.js.map +1 -1
  15. package/dist/browser/ShareServiceClient.d.ts +1 -1
  16. package/dist/browser/ShareServiceClient.d.ts.map +1 -1
  17. package/dist/browser/ShareServiceClient.js +3 -3
  18. package/dist/browser/ShareServiceClient.js.map +1 -1
  19. package/dist/browser/StorageClient.d.ts +2 -2
  20. package/dist/browser/StorageClient.d.ts.map +1 -1
  21. package/dist/browser/StorageClient.js.map +1 -1
  22. package/dist/browser/index-browser.d.mts.map +1 -1
  23. package/dist/browser/index-browser.mjs.map +1 -1
  24. package/dist/browser/index.d.ts +1 -7
  25. package/dist/browser/index.js +1 -7
  26. package/dist/commonjs/AccountSASSignatureValues.d.ts +1 -1
  27. package/dist/commonjs/AccountSASSignatureValues.d.ts.map +1 -1
  28. package/dist/commonjs/AccountSASSignatureValues.js.map +1 -1
  29. package/dist/commonjs/Clients.d.ts +1 -1
  30. package/dist/commonjs/Clients.d.ts.map +1 -1
  31. package/dist/commonjs/Clients.js +15 -15
  32. package/dist/commonjs/Clients.js.map +1 -1
  33. package/dist/commonjs/FileSASSignatureValues.d.ts +1 -1
  34. package/dist/commonjs/FileSASSignatureValues.d.ts.map +1 -1
  35. package/dist/commonjs/FileSASSignatureValues.js.map +1 -1
  36. package/dist/commonjs/Pipeline.d.ts +2 -4
  37. package/dist/commonjs/Pipeline.d.ts.map +1 -1
  38. package/dist/commonjs/Pipeline.js +12 -20
  39. package/dist/commonjs/Pipeline.js.map +1 -1
  40. package/dist/commonjs/ShareServiceClient.d.ts +1 -1
  41. package/dist/commonjs/ShareServiceClient.d.ts.map +1 -1
  42. package/dist/commonjs/ShareServiceClient.js +9 -9
  43. package/dist/commonjs/ShareServiceClient.js.map +1 -1
  44. package/dist/commonjs/StorageClient.d.ts +2 -2
  45. package/dist/commonjs/StorageClient.d.ts.map +1 -1
  46. package/dist/commonjs/StorageClient.js.map +1 -1
  47. package/dist/commonjs/index.d.ts +1 -9
  48. package/dist/commonjs/index.d.ts.map +1 -1
  49. package/dist/commonjs/index.js +13 -18
  50. package/dist/commonjs/index.js.map +1 -1
  51. package/dist/commonjs/utils/utils.d.ts +1 -1
  52. package/dist/commonjs/utils/utils.d.ts.map +1 -1
  53. package/dist/commonjs/utils/utils.js +5 -5
  54. package/dist/commonjs/utils/utils.js.map +1 -1
  55. package/dist/esm/AccountSASSignatureValues.d.ts +1 -1
  56. package/dist/esm/AccountSASSignatureValues.d.ts.map +1 -1
  57. package/dist/esm/AccountSASSignatureValues.js.map +1 -1
  58. package/dist/esm/Clients.d.ts +1 -1
  59. package/dist/esm/Clients.d.ts.map +1 -1
  60. package/dist/esm/Clients.js +3 -3
  61. package/dist/esm/Clients.js.map +1 -1
  62. package/dist/esm/FileSASSignatureValues.d.ts +1 -1
  63. package/dist/esm/FileSASSignatureValues.d.ts.map +1 -1
  64. package/dist/esm/FileSASSignatureValues.js.map +1 -1
  65. package/dist/esm/Pipeline.d.ts +2 -4
  66. package/dist/esm/Pipeline.d.ts.map +1 -1
  67. package/dist/esm/Pipeline.js +1 -9
  68. package/dist/esm/Pipeline.js.map +1 -1
  69. package/dist/esm/ShareServiceClient.d.ts +1 -1
  70. package/dist/esm/ShareServiceClient.d.ts.map +1 -1
  71. package/dist/esm/ShareServiceClient.js +3 -3
  72. package/dist/esm/ShareServiceClient.js.map +1 -1
  73. package/dist/esm/StorageClient.d.ts +2 -2
  74. package/dist/esm/StorageClient.d.ts.map +1 -1
  75. package/dist/esm/StorageClient.js.map +1 -1
  76. package/dist/esm/index.d.ts +1 -9
  77. package/dist/esm/index.d.ts.map +1 -1
  78. package/dist/esm/index.js +1 -9
  79. package/dist/esm/index.js.map +1 -1
  80. package/dist/esm/utils/utils.d.ts +1 -1
  81. package/dist/esm/utils/utils.d.ts.map +1 -1
  82. package/dist/esm/utils/utils.js +2 -2
  83. package/dist/esm/utils/utils.js.map +1 -1
  84. package/dist/react-native/AccountSASSignatureValues.d.ts +1 -1
  85. package/dist/react-native/AccountSASSignatureValues.d.ts.map +1 -1
  86. package/dist/react-native/AccountSASSignatureValues.js.map +1 -1
  87. package/dist/react-native/Clients.d.ts +1 -1
  88. package/dist/react-native/Clients.d.ts.map +1 -1
  89. package/dist/react-native/Clients.js +3 -3
  90. package/dist/react-native/Clients.js.map +1 -1
  91. package/dist/react-native/FileSASSignatureValues.d.ts +1 -1
  92. package/dist/react-native/FileSASSignatureValues.d.ts.map +1 -1
  93. package/dist/react-native/FileSASSignatureValues.js.map +1 -1
  94. package/dist/react-native/Pipeline.d.ts +2 -4
  95. package/dist/react-native/Pipeline.d.ts.map +1 -1
  96. package/dist/react-native/Pipeline.js +1 -9
  97. package/dist/react-native/Pipeline.js.map +1 -1
  98. package/dist/react-native/ShareServiceClient.d.ts +1 -1
  99. package/dist/react-native/ShareServiceClient.d.ts.map +1 -1
  100. package/dist/react-native/ShareServiceClient.js +3 -3
  101. package/dist/react-native/ShareServiceClient.js.map +1 -1
  102. package/dist/react-native/StorageClient.d.ts +2 -2
  103. package/dist/react-native/StorageClient.d.ts.map +1 -1
  104. package/dist/react-native/StorageClient.js.map +1 -1
  105. package/dist/react-native/index.d.ts +1 -9
  106. package/dist/react-native/index.d.ts.map +1 -1
  107. package/dist/react-native/index.js +1 -9
  108. package/dist/react-native/index.js.map +1 -1
  109. package/dist/react-native/utils/utils.d.ts +1 -1
  110. package/dist/react-native/utils/utils.d.ts.map +1 -1
  111. package/dist/react-native/utils/utils.js +2 -2
  112. package/dist/react-native/utils/utils.js.map +1 -1
  113. package/package.json +2 -2
  114. package/dist/browser/StorageRetryPolicyFactory.d.ts +0 -56
  115. package/dist/browser/StorageRetryPolicyFactory.d.ts.map +0 -1
  116. package/dist/browser/StorageRetryPolicyFactory.js +0 -26
  117. package/dist/browser/StorageRetryPolicyFactory.js.map +0 -1
  118. package/dist/browser/policies/StorageRetryPolicy.d.ts +0 -75
  119. package/dist/browser/policies/StorageRetryPolicy.d.ts.map +0 -1
  120. package/dist/browser/policies/StorageRetryPolicy.js +0 -220
  121. package/dist/browser/policies/StorageRetryPolicy.js.map +0 -1
  122. package/dist/browser/policies/StorageRetryPolicyV2.d.ts +0 -24
  123. package/dist/browser/policies/StorageRetryPolicyV2.d.ts.map +0 -1
  124. package/dist/browser/policies/StorageRetryPolicyV2.js +0 -176
  125. package/dist/browser/policies/StorageRetryPolicyV2.js.map +0 -1
  126. package/dist/commonjs/StorageRetryPolicyFactory.d.ts +0 -56
  127. package/dist/commonjs/StorageRetryPolicyFactory.d.ts.map +0 -1
  128. package/dist/commonjs/StorageRetryPolicyFactory.js +0 -31
  129. package/dist/commonjs/StorageRetryPolicyFactory.js.map +0 -1
  130. package/dist/commonjs/policies/StorageRetryPolicy.d.ts +0 -75
  131. package/dist/commonjs/policies/StorageRetryPolicy.d.ts.map +0 -1
  132. package/dist/commonjs/policies/StorageRetryPolicy.js +0 -225
  133. package/dist/commonjs/policies/StorageRetryPolicy.js.map +0 -1
  134. package/dist/commonjs/policies/StorageRetryPolicyV2.d.ts +0 -24
  135. package/dist/commonjs/policies/StorageRetryPolicyV2.d.ts.map +0 -1
  136. package/dist/commonjs/policies/StorageRetryPolicyV2.js +0 -180
  137. package/dist/commonjs/policies/StorageRetryPolicyV2.js.map +0 -1
  138. package/dist/esm/StorageRetryPolicyFactory.d.ts +0 -56
  139. package/dist/esm/StorageRetryPolicyFactory.d.ts.map +0 -1
  140. package/dist/esm/StorageRetryPolicyFactory.js +0 -26
  141. package/dist/esm/StorageRetryPolicyFactory.js.map +0 -1
  142. package/dist/esm/policies/StorageRetryPolicy.d.ts +0 -75
  143. package/dist/esm/policies/StorageRetryPolicy.d.ts.map +0 -1
  144. package/dist/esm/policies/StorageRetryPolicy.js +0 -220
  145. package/dist/esm/policies/StorageRetryPolicy.js.map +0 -1
  146. package/dist/esm/policies/StorageRetryPolicyV2.d.ts +0 -24
  147. package/dist/esm/policies/StorageRetryPolicyV2.d.ts.map +0 -1
  148. package/dist/esm/policies/StorageRetryPolicyV2.js +0 -176
  149. package/dist/esm/policies/StorageRetryPolicyV2.js.map +0 -1
  150. package/dist/react-native/StorageRetryPolicyFactory.d.ts +0 -56
  151. package/dist/react-native/StorageRetryPolicyFactory.d.ts.map +0 -1
  152. package/dist/react-native/StorageRetryPolicyFactory.js +0 -26
  153. package/dist/react-native/StorageRetryPolicyFactory.js.map +0 -1
  154. package/dist/react-native/policies/StorageRetryPolicy.d.ts +0 -75
  155. package/dist/react-native/policies/StorageRetryPolicy.d.ts.map +0 -1
  156. package/dist/react-native/policies/StorageRetryPolicy.js +0 -220
  157. package/dist/react-native/policies/StorageRetryPolicy.js.map +0 -1
  158. package/dist/react-native/policies/StorageRetryPolicyV2.d.ts +0 -24
  159. package/dist/react-native/policies/StorageRetryPolicyV2.d.ts.map +0 -1
  160. package/dist/react-native/policies/StorageRetryPolicyV2.js +0 -176
  161. package/dist/react-native/policies/StorageRetryPolicyV2.js.map +0 -1
@@ -1,176 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { AbortError } from "@azure/abort-controller";
4
- import { isRestError, RestError } from "@azure/core-rest-pipeline";
5
- import { getErrorMessage } from "@azure/core-util";
6
- import { URLConstants } from "../utils/constants.js";
7
- import { delay, setURLParameter } from "../utils/utils.common.js";
8
- import { logger } from "../log.js";
9
- /**
10
- * Name of the {@link storageRetryPolicy}
11
- */
12
- export const storageRetryPolicyName = "storageRetryPolicy";
13
- /**
14
- * RetryPolicy types.
15
- */
16
- export var StorageRetryPolicyType;
17
- (function (StorageRetryPolicyType) {
18
- /**
19
- * Exponential retry. Retry time delay grows exponentially.
20
- */
21
- StorageRetryPolicyType[StorageRetryPolicyType["EXPONENTIAL"] = 0] = "EXPONENTIAL";
22
- /**
23
- * Linear retry. Retry time delay grows linearly.
24
- */
25
- StorageRetryPolicyType[StorageRetryPolicyType["FIXED"] = 1] = "FIXED";
26
- })(StorageRetryPolicyType || (StorageRetryPolicyType = {}));
27
- // Default values of StorageRetryOptions
28
- const DEFAULT_RETRY_OPTIONS = {
29
- maxRetryDelayInMs: 120 * 1000,
30
- maxTries: 4,
31
- retryDelayInMs: 4 * 1000,
32
- retryPolicyType: StorageRetryPolicyType.EXPONENTIAL,
33
- secondaryHost: "",
34
- tryTimeoutInMs: undefined, // Use server side default timeout strategy
35
- };
36
- const retriableErrors = [
37
- "ETIMEDOUT",
38
- "ESOCKETTIMEDOUT",
39
- "ECONNREFUSED",
40
- "ECONNRESET",
41
- "ENOENT",
42
- "ENOTFOUND",
43
- "TIMEOUT",
44
- "EPIPE",
45
- "REQUEST_SEND_ERROR",
46
- ];
47
- const RETRY_ABORT_ERROR = new AbortError("The operation was aborted.");
48
- /**
49
- * Retry policy with exponential retry and linear retry implemented.
50
- */
51
- export function storageRetryPolicy(options = {}) {
52
- var _a, _b, _c, _d, _e;
53
- const retryPolicyType = (_a = options.retryPolicyType) !== null && _a !== void 0 ? _a : DEFAULT_RETRY_OPTIONS.retryPolicyType;
54
- const maxTries = (_b = options.maxTries) !== null && _b !== void 0 ? _b : DEFAULT_RETRY_OPTIONS.maxTries;
55
- const retryDelayInMs = (_c = options.retryDelayInMs) !== null && _c !== void 0 ? _c : DEFAULT_RETRY_OPTIONS.retryDelayInMs;
56
- const maxRetryDelayInMs = (_d = options.maxRetryDelayInMs) !== null && _d !== void 0 ? _d : DEFAULT_RETRY_OPTIONS.maxRetryDelayInMs;
57
- const tryTimeoutInMs = (_e = options.tryTimeoutInMs) !== null && _e !== void 0 ? _e : DEFAULT_RETRY_OPTIONS.tryTimeoutInMs;
58
- function shouldRetry({ isPrimaryRetry, attempt, response, error, }) {
59
- var _a, _b;
60
- if (attempt >= maxTries) {
61
- logger.info(`RetryPolicy: Attempt(s) ${attempt} >= maxTries ${maxTries}, no further try.`);
62
- return false;
63
- }
64
- if (error) {
65
- for (const retriableError of retriableErrors) {
66
- if (error.name.toUpperCase().includes(retriableError) ||
67
- error.message.toUpperCase().includes(retriableError) ||
68
- (error.code && error.code.toString().toUpperCase() === retriableError)) {
69
- logger.info(`RetryPolicy: Network error ${retriableError} found, will retry.`);
70
- return true;
71
- }
72
- }
73
- if ((error === null || error === void 0 ? void 0 : error.code) === "PARSE_ERROR" &&
74
- (error === null || error === void 0 ? void 0 : error.message.startsWith(`Error "Error: Unclosed root tag`))) {
75
- logger.info("RetryPolicy: Incomplete XML response likely due to service timeout, will retry.");
76
- return true;
77
- }
78
- }
79
- // If attempt was against the secondary & it returned a StatusNotFound (404), then
80
- // the resource was not found. This may be due to replication delay. So, in this
81
- // case, we'll never try the secondary again for this operation.
82
- if (response || error) {
83
- const statusCode = (_b = (_a = response === null || response === void 0 ? void 0 : response.status) !== null && _a !== void 0 ? _a : error === null || error === void 0 ? void 0 : error.statusCode) !== null && _b !== void 0 ? _b : 0;
84
- if (!isPrimaryRetry && statusCode === 404) {
85
- logger.info(`RetryPolicy: Secondary access with 404, will retry.`);
86
- return true;
87
- }
88
- // Server internal error or server timeout
89
- if (statusCode === 503 || statusCode === 500) {
90
- logger.info(`RetryPolicy: Will retry for status code ${statusCode}.`);
91
- return true;
92
- }
93
- }
94
- // [Copy source error code] Feature is pending on service side, skip retry on copy source error for now.
95
- // if (response) {
96
- // // Retry select Copy Source Error Codes.
97
- // if (response?.status >= 400) {
98
- // const copySourceError = response.headers.get(HeaderConstants.X_MS_CopySourceErrorCode);
99
- // if (copySourceError !== undefined) {
100
- // switch (copySourceError)
101
- // {
102
- // case "InternalError":
103
- // case "OperationTimedOut":
104
- // case "ServerBusy":
105
- // return true;
106
- // }
107
- // }
108
- // }
109
- // }
110
- return false;
111
- }
112
- function calculateDelay(isPrimaryRetry, attempt) {
113
- let delayTimeInMs = 0;
114
- if (isPrimaryRetry) {
115
- switch (retryPolicyType) {
116
- case StorageRetryPolicyType.EXPONENTIAL:
117
- delayTimeInMs = Math.min((Math.pow(2, attempt - 1) - 1) * retryDelayInMs, maxRetryDelayInMs);
118
- break;
119
- case StorageRetryPolicyType.FIXED:
120
- delayTimeInMs = retryDelayInMs;
121
- break;
122
- }
123
- }
124
- else {
125
- delayTimeInMs = Math.random() * 1000;
126
- }
127
- logger.info(`RetryPolicy: Delay for ${delayTimeInMs}ms`);
128
- return delayTimeInMs;
129
- }
130
- return {
131
- name: storageRetryPolicyName,
132
- async sendRequest(request, next) {
133
- // Set the server-side timeout query parameter "timeout=[seconds]"
134
- if (tryTimeoutInMs) {
135
- request.url = setURLParameter(request.url, URLConstants.Parameters.TIMEOUT, String(Math.floor(tryTimeoutInMs / 1000)));
136
- }
137
- const primaryUrl = request.url;
138
- let secondaryHas404 = false;
139
- let attempt = 1;
140
- let retryAgain = true;
141
- let response;
142
- let error;
143
- while (retryAgain) {
144
- const isPrimaryRetry = true;
145
- request.url = primaryUrl;
146
- response = undefined;
147
- error = undefined;
148
- try {
149
- logger.info(`RetryPolicy: =====> Try=${attempt} ${isPrimaryRetry ? "Primary" : "Secondary"}`);
150
- response = await next(request);
151
- secondaryHas404 = secondaryHas404 || (!isPrimaryRetry && response.status === 404);
152
- }
153
- catch (e) {
154
- if (isRestError(e)) {
155
- logger.error(`RetryPolicy: Caught error, message: ${e.message}, code: ${e.code}`);
156
- error = e;
157
- }
158
- else {
159
- logger.error(`RetryPolicy: Caught error, message: ${getErrorMessage(e)}`);
160
- throw e;
161
- }
162
- }
163
- retryAgain = shouldRetry({ isPrimaryRetry, attempt, response, error });
164
- if (retryAgain) {
165
- await delay(calculateDelay(isPrimaryRetry, attempt), request.abortSignal, RETRY_ABORT_ERROR);
166
- }
167
- attempt++;
168
- }
169
- if (response) {
170
- return response;
171
- }
172
- throw error !== null && error !== void 0 ? error : new RestError("RetryPolicy failed without known error.");
173
- },
174
- };
175
- }
176
- //# sourceMappingURL=StorageRetryPolicyV2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StorageRetryPolicyV2.js","sourceRoot":"","sources":["../../../src/policies/StorageRetryPolicyV2.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAOrD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAN,IAAY,sBASX;AATD,WAAY,sBAAsB;IAChC;;OAEG;IACH,iFAAW,CAAA;IACX;;OAEG;IACH,qEAAK,CAAA;AACP,CAAC,EATW,sBAAsB,KAAtB,sBAAsB,QASjC;AAED,wCAAwC;AACxC,MAAM,qBAAqB,GAAG;IAC5B,iBAAiB,EAAE,GAAG,GAAG,IAAI;IAC7B,QAAQ,EAAE,CAAC;IACX,cAAc,EAAE,CAAC,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AC;YACZ,CAAC;YACD,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,QAAQ,CAAC;YAClB,CAAC;YACD,MAAM,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,SAAS,CAAC,yCAAyC,CAAC,CAAC;QAC1E,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AbortError } from \"@azure/abort-controller\";\nimport type {\n PipelinePolicy,\n PipelineRequest,\n SendRequest,\n PipelineResponse,\n} from \"@azure/core-rest-pipeline\";\nimport { isRestError, RestError } from \"@azure/core-rest-pipeline\";\nimport { getErrorMessage } from \"@azure/core-util\";\nimport type { StorageRetryOptions } from \"../StorageRetryPolicyFactory.js\";\nimport { URLConstants } from \"../utils/constants.js\";\nimport { delay, setURLParameter } from \"../utils/utils.common.js\";\nimport { logger } from \"../log.js\";\n\n/**\n * Name of the {@link storageRetryPolicy}\n */\nexport const storageRetryPolicyName = \"storageRetryPolicy\";\n\n/**\n * RetryPolicy types.\n */\nexport enum StorageRetryPolicyType {\n /**\n * Exponential retry. Retry time delay grows exponentially.\n */\n EXPONENTIAL,\n /**\n * Linear retry. Retry time delay grows linearly.\n */\n FIXED,\n}\n\n// Default values of StorageRetryOptions\nconst DEFAULT_RETRY_OPTIONS = {\n maxRetryDelayInMs: 120 * 1000,\n maxTries: 4,\n retryDelayInMs: 4 * 1000,\n retryPolicyType: StorageRetryPolicyType.EXPONENTIAL,\n secondaryHost: \"\",\n tryTimeoutInMs: undefined, // Use server side default timeout strategy\n} as const;\n\nconst retriableErrors = [\n \"ETIMEDOUT\",\n \"ESOCKETTIMEDOUT\",\n \"ECONNREFUSED\",\n \"ECONNRESET\",\n \"ENOENT\",\n \"ENOTFOUND\",\n \"TIMEOUT\",\n \"EPIPE\",\n \"REQUEST_SEND_ERROR\",\n] as const;\n\nconst RETRY_ABORT_ERROR = new AbortError(\"The operation was aborted.\");\n\n/**\n * Retry policy with exponential retry and linear retry implemented.\n */\nexport function storageRetryPolicy(options: StorageRetryOptions = {}): PipelinePolicy {\n const retryPolicyType = options.retryPolicyType ?? DEFAULT_RETRY_OPTIONS.retryPolicyType;\n const maxTries = options.maxTries ?? DEFAULT_RETRY_OPTIONS.maxTries;\n const retryDelayInMs = options.retryDelayInMs ?? DEFAULT_RETRY_OPTIONS.retryDelayInMs;\n const maxRetryDelayInMs = options.maxRetryDelayInMs ?? DEFAULT_RETRY_OPTIONS.maxRetryDelayInMs;\n const tryTimeoutInMs = options.tryTimeoutInMs ?? DEFAULT_RETRY_OPTIONS.tryTimeoutInMs;\n\n function shouldRetry({\n isPrimaryRetry,\n attempt,\n response,\n error,\n }: {\n isPrimaryRetry: boolean;\n attempt: number;\n response?: PipelineResponse;\n error?: RestError;\n }): boolean {\n if (attempt >= maxTries) {\n logger.info(`RetryPolicy: Attempt(s) ${attempt} >= maxTries ${maxTries}, no further try.`);\n return false;\n }\n if (error) {\n for (const retriableError of retriableErrors) {\n if (\n error.name.toUpperCase().includes(retriableError) ||\n error.message.toUpperCase().includes(retriableError) ||\n (error.code && error.code.toString().toUpperCase() === retriableError)\n ) {\n logger.info(`RetryPolicy: Network error ${retriableError} found, will retry.`);\n return true;\n }\n }\n if (\n error?.code === \"PARSE_ERROR\" &&\n error?.message.startsWith(`Error \"Error: Unclosed root tag`)\n ) {\n logger.info(\n \"RetryPolicy: Incomplete XML response likely due to service timeout, will retry.\",\n );\n return true;\n }\n }\n // If attempt was against the secondary & it returned a StatusNotFound (404), then\n // the resource was not found. This may be due to replication delay. So, in this\n // case, we'll never try the secondary again for this operation.\n if (response || error) {\n const statusCode = response?.status ?? error?.statusCode ?? 0;\n if (!isPrimaryRetry && statusCode === 404) {\n logger.info(`RetryPolicy: Secondary access with 404, will retry.`);\n return true;\n }\n\n // Server internal error or server timeout\n if (statusCode === 503 || statusCode === 500) {\n logger.info(`RetryPolicy: Will retry for status code ${statusCode}.`);\n return true;\n }\n }\n\n // [Copy source error code] Feature is pending on service side, skip retry on copy source error for now.\n // if (response) {\n // // Retry select Copy Source Error Codes.\n // if (response?.status >= 400) {\n // const copySourceError = response.headers.get(HeaderConstants.X_MS_CopySourceErrorCode);\n // if (copySourceError !== undefined) {\n // switch (copySourceError)\n // {\n // case \"InternalError\":\n // case \"OperationTimedOut\":\n // case \"ServerBusy\":\n // return true;\n // }\n // }\n // }\n // }\n\n return false;\n }\n function calculateDelay(isPrimaryRetry: boolean, attempt: number): number {\n let delayTimeInMs = 0;\n\n if (isPrimaryRetry) {\n switch (retryPolicyType) {\n case StorageRetryPolicyType.EXPONENTIAL:\n delayTimeInMs = Math.min(\n (Math.pow(2, attempt - 1) - 1) * retryDelayInMs,\n maxRetryDelayInMs,\n );\n break;\n case StorageRetryPolicyType.FIXED:\n delayTimeInMs = retryDelayInMs;\n break;\n }\n } else {\n delayTimeInMs = Math.random() * 1000;\n }\n\n logger.info(`RetryPolicy: Delay for ${delayTimeInMs}ms`);\n return delayTimeInMs;\n }\n return {\n name: storageRetryPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n // Set the server-side timeout query parameter \"timeout=[seconds]\"\n if (tryTimeoutInMs) {\n request.url = setURLParameter(\n request.url,\n URLConstants.Parameters.TIMEOUT,\n String(Math.floor(tryTimeoutInMs / 1000)),\n );\n }\n const primaryUrl = request.url;\n let secondaryHas404 = false;\n let attempt = 1;\n let retryAgain = true;\n let response: PipelineResponse | undefined;\n let error: RestError | undefined;\n while (retryAgain) {\n const isPrimaryRetry: boolean = true;\n request.url = primaryUrl;\n response = undefined;\n error = undefined;\n try {\n logger.info(\n `RetryPolicy: =====> Try=${attempt} ${isPrimaryRetry ? \"Primary\" : \"Secondary\"}`,\n );\n response = await next(request);\n secondaryHas404 = secondaryHas404 || (!isPrimaryRetry && response.status === 404);\n } catch (e: unknown) {\n if (isRestError(e)) {\n logger.error(`RetryPolicy: Caught error, message: ${e.message}, code: ${e.code}`);\n error = e;\n } else {\n logger.error(`RetryPolicy: Caught error, message: ${getErrorMessage(e)}`);\n throw e;\n }\n }\n retryAgain = shouldRetry({ isPrimaryRetry, attempt, response, error });\n if (retryAgain) {\n await delay(\n calculateDelay(isPrimaryRetry, attempt),\n request.abortSignal,\n RETRY_ABORT_ERROR,\n );\n }\n attempt++;\n }\n if (response) {\n return response;\n }\n throw error ?? new RestError(\"RetryPolicy failed without known error.\");\n },\n };\n}\n"]}
@@ -1,56 +0,0 @@
1
- import type { RequestPolicy, RequestPolicyOptionsLike as RequestPolicyOptions, RequestPolicyFactory } from "@azure/core-http-compat";
2
- import { StorageRetryPolicy, StorageRetryPolicyType } from "./policies/StorageRetryPolicy.js";
3
- export { StorageRetryPolicyType, StorageRetryPolicy };
4
- /**
5
- * Storage Blob retry options interface.
6
- */
7
- export interface StorageRetryOptions {
8
- /**
9
- * Optional. StorageRetryPolicyType, default is exponential retry policy.
10
- */
11
- readonly retryPolicyType?: StorageRetryPolicyType;
12
- /**
13
- * Optional. Max try number of attempts, default is 4.
14
- * A value of 1 means 1 try and no retries.
15
- * A value smaller than 1 means default retry number of attempts.
16
- */
17
- readonly maxTries?: number;
18
- /**
19
- * Optional. Indicates the maximum time in ms allowed for any single try of an HTTP request.
20
- * A value of zero or undefined means no default timeout on SDK client, Azure
21
- * Storage server's default timeout policy will be used.
22
- *
23
- * @see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations
24
- */
25
- readonly tryTimeoutInMs?: number;
26
- /**
27
- * Optional. Specifies the amount of delay to use before retrying an operation (default is 4s or 4 * 1000ms).
28
- * The delay increases (exponentially or linearly) with each retry up to a maximum specified by
29
- * maxRetryDelayInMs. If you specify 0, then you must also specify 0 for maxRetryDelayInMs.
30
- */
31
- readonly retryDelayInMs?: number;
32
- /**
33
- * Optional. Specifies the maximum delay allowed before retrying an operation (default is 120s or 120 * 1000ms).
34
- * If you specify 0, then you must also specify 0 for retryDelayInMs.
35
- */
36
- readonly maxRetryDelayInMs?: number;
37
- }
38
- /**
39
- * StorageRetryPolicyFactory is a factory class helping generating {@link StorageRetryPolicy} objects.
40
- */
41
- export declare class StorageRetryPolicyFactory implements RequestPolicyFactory {
42
- private retryOptions?;
43
- /**
44
- * Creates an instance of StorageRetryPolicyFactory.
45
- * @param retryOptions -
46
- */
47
- constructor(retryOptions?: StorageRetryOptions);
48
- /**
49
- * Creates a StorageRetryPolicy object.
50
- *
51
- * @param nextPolicy -
52
- * @param options -
53
- */
54
- create(nextPolicy: RequestPolicy, options: RequestPolicyOptions): StorageRetryPolicy;
55
- }
56
- //# sourceMappingURL=StorageRetryPolicyFactory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StorageRetryPolicyFactory.d.ts","sourceRoot":"","sources":["../../src/StorageRetryPolicyFactory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,IAAI,oBAAoB,EAChD,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAE9F,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,sBAAsB,CAAC;IAElD;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;;OAMG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAEjC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAEjC;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAED;;GAEG;AACH,qBAAa,yBAA0B,YAAW,oBAAoB;IACpE,OAAO,CAAC,YAAY,CAAC,CAAsB;IAE3C;;;OAGG;gBACS,YAAY,CAAC,EAAE,mBAAmB;IAI9C;;;;;OAKG;IACI,MAAM,CAAC,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,oBAAoB,GAAG,kBAAkB;CAG5F"}
@@ -1,31 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.StorageRetryPolicyFactory = exports.StorageRetryPolicy = exports.StorageRetryPolicyType = void 0;
6
- const StorageRetryPolicy_js_1 = require("./policies/StorageRetryPolicy.js");
7
- Object.defineProperty(exports, "StorageRetryPolicy", { enumerable: true, get: function () { return StorageRetryPolicy_js_1.StorageRetryPolicy; } });
8
- Object.defineProperty(exports, "StorageRetryPolicyType", { enumerable: true, get: function () { return StorageRetryPolicy_js_1.StorageRetryPolicyType; } });
9
- /**
10
- * StorageRetryPolicyFactory is a factory class helping generating {@link StorageRetryPolicy} objects.
11
- */
12
- class StorageRetryPolicyFactory {
13
- /**
14
- * Creates an instance of StorageRetryPolicyFactory.
15
- * @param retryOptions -
16
- */
17
- constructor(retryOptions) {
18
- this.retryOptions = retryOptions;
19
- }
20
- /**
21
- * Creates a StorageRetryPolicy object.
22
- *
23
- * @param nextPolicy -
24
- * @param options -
25
- */
26
- create(nextPolicy, options) {
27
- return new StorageRetryPolicy_js_1.StorageRetryPolicy(nextPolicy, options, this.retryOptions);
28
- }
29
- }
30
- exports.StorageRetryPolicyFactory = StorageRetryPolicyFactory;
31
- //# sourceMappingURL=StorageRetryPolicyFactory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StorageRetryPolicyFactory.js","sourceRoot":"","sources":["../../src/StorageRetryPolicyFactory.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAOlC,4EAA8F;AAE7D,mGAFxB,0CAAkB,OAEwB;AAA1C,uGAFoB,8CAAsB,OAEpB;AAyC/B;;GAEG;AACH,MAAa,yBAAyB;IAGpC;;;OAGG;IACH,YAAY,YAAkC;QAC5C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,UAAyB,EAAE,OAA6B;QACpE,OAAO,IAAI,0CAAkB,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACxE,CAAC;CACF;AApBD,8DAoBC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n RequestPolicy,\n RequestPolicyOptionsLike as RequestPolicyOptions,\n RequestPolicyFactory,\n} from \"@azure/core-http-compat\";\nimport { StorageRetryPolicy, StorageRetryPolicyType } from \"./policies/StorageRetryPolicy.js\";\n\nexport { StorageRetryPolicyType, StorageRetryPolicy };\n\n/**\n * Storage Blob retry options interface.\n */\nexport interface StorageRetryOptions {\n /**\n * Optional. StorageRetryPolicyType, default is exponential retry policy.\n */\n readonly retryPolicyType?: StorageRetryPolicyType;\n\n /**\n * Optional. Max try number of attempts, default is 4.\n * A value of 1 means 1 try and no retries.\n * A value smaller than 1 means default retry number of attempts.\n */\n readonly maxTries?: number;\n\n /**\n * Optional. Indicates the maximum time in ms allowed for any single try of an HTTP request.\n * A value of zero or undefined means no default timeout on SDK client, Azure\n * Storage server's default timeout policy will be used.\n *\n * @see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations\n */\n readonly tryTimeoutInMs?: number;\n\n /**\n * Optional. Specifies the amount of delay to use before retrying an operation (default is 4s or 4 * 1000ms).\n * The delay increases (exponentially or linearly) with each retry up to a maximum specified by\n * maxRetryDelayInMs. If you specify 0, then you must also specify 0 for maxRetryDelayInMs.\n */\n readonly retryDelayInMs?: number;\n\n /**\n * Optional. Specifies the maximum delay allowed before retrying an operation (default is 120s or 120 * 1000ms).\n * If you specify 0, then you must also specify 0 for retryDelayInMs.\n */\n readonly maxRetryDelayInMs?: number;\n}\n\n/**\n * StorageRetryPolicyFactory is a factory class helping generating {@link StorageRetryPolicy} objects.\n */\nexport class StorageRetryPolicyFactory implements RequestPolicyFactory {\n private retryOptions?: StorageRetryOptions;\n\n /**\n * Creates an instance of StorageRetryPolicyFactory.\n * @param retryOptions -\n */\n constructor(retryOptions?: StorageRetryOptions) {\n this.retryOptions = retryOptions;\n }\n\n /**\n * Creates a StorageRetryPolicy object.\n *\n * @param nextPolicy -\n * @param options -\n */\n public create(nextPolicy: RequestPolicy, options: RequestPolicyOptions): StorageRetryPolicy {\n return new StorageRetryPolicy(nextPolicy, options, this.retryOptions);\n }\n}\n"]}
@@ -1,75 +0,0 @@
1
- import type { RequestPolicy, RequestPolicyOptionsLike as RequestPolicyOptions, RequestPolicyFactory, WebResourceLike as WebResource, CompatResponse as HttpOperationResponse } from "@azure/core-http-compat";
2
- import { BaseRequestPolicy } from "@azure/storage-blob";
3
- import type { RestError } from "@azure/core-rest-pipeline";
4
- import type { StorageRetryOptions } from "../StorageRetryPolicyFactory.js";
5
- /**
6
- * A factory method used to generated a RetryPolicy factory.
7
- *
8
- * @param retryOptions -
9
- */
10
- export declare function NewRetryPolicyFactory(retryOptions?: StorageRetryOptions): RequestPolicyFactory;
11
- /**
12
- * RetryPolicy types.
13
- */
14
- export declare enum StorageRetryPolicyType {
15
- /**
16
- * Exponential retry. Retry time delay grows exponentially.
17
- */
18
- EXPONENTIAL = 0,
19
- /**
20
- * Linear retry. Retry time delay grows linearly.
21
- */
22
- FIXED = 1
23
- }
24
- /**
25
- * Retry policy with exponential retry and linear retry implemented.
26
- */
27
- export declare class StorageRetryPolicy extends BaseRequestPolicy {
28
- /**
29
- * RetryOptions.
30
- */
31
- private readonly retryOptions;
32
- /**
33
- * Creates an instance of RetryPolicy.
34
- *
35
- * @param nextPolicy -
36
- * @param options -
37
- * @param retryOptions -
38
- */
39
- constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions, retryOptions?: StorageRetryOptions);
40
- /**
41
- * Sends request.
42
- *
43
- * @param request -
44
- */
45
- sendRequest(request: WebResource): Promise<HttpOperationResponse>;
46
- /**
47
- * Decide and perform next retry. Won't mutate request parameter.
48
- *
49
- * @param request -
50
- * @param secondaryHas404 - If attempt was against the secondary & it returned a StatusNotFound (404), then
51
- * the resource was not found. This may be due to replication delay. So, in this
52
- * case, we'll never try the secondary again for this operation.
53
- * @param attempt - How many retries has been attempted to performed, starting from 1, which includes
54
- * the attempt will be performed by this method call.
55
- */
56
- protected attemptSendRequest(request: WebResource, secondaryHas404: boolean, attempt: number): Promise<HttpOperationResponse>;
57
- /**
58
- * Decide whether to retry according to last HTTP response and retry counters.
59
- *
60
- * @param isPrimaryRetry -
61
- * @param attempt -
62
- * @param response -
63
- * @param err -
64
- */
65
- protected shouldRetry(isPrimaryRetry: boolean, attempt: number, response?: HttpOperationResponse, err?: RestError): boolean;
66
- /**
67
- * Delay a calculated time between retries.
68
- *
69
- * @param isPrimaryRetry -
70
- * @param attempt -
71
- * @param abortSignal -
72
- */
73
- private delay;
74
- }
75
- //# sourceMappingURL=StorageRetryPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StorageRetryPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/StorageRetryPolicy.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,IAAI,oBAAoB,EAChD,oBAAoB,EACpB,eAAe,IAAI,WAAW,EAC9B,cAAc,IAAI,qBAAqB,EACxC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAK3E;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,CAAC,EAAE,mBAAmB,GAAG,oBAAoB,CAM9F;AAED;;GAEG;AACH,oBAAY,sBAAsB;IAChC;;OAEG;IACH,WAAW,IAAA;IACX;;OAEG;IACH,KAAK,IAAA;CACN;AAaD;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,iBAAiB;IACvD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IAEnD;;;;;;OAMG;gBAED,UAAU,EAAE,aAAa,EACzB,OAAO,EAAE,oBAAoB,EAC7B,YAAY,GAAE,mBAA2C;IAqC3D;;;;OAIG;IACU,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAI9E;;;;;;;;;OASG;cACa,kBAAkB,CAChC,OAAO,EAAE,WAAW,EACpB,eAAe,EAAE,OAAO,EACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,qBAAqB,CAAC;IAkCjC;;;;;;;OAOG;IACH,SAAS,CAAC,WAAW,CACnB,cAAc,EAAE,OAAO,EACvB,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,qBAAqB,EAChC,GAAG,CAAC,EAAE,SAAS,GACd,OAAO;IA+EV;;;;;;OAMG;YACW,KAAK;CA0BpB"}
@@ -1,225 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.StorageRetryPolicy = exports.StorageRetryPolicyType = void 0;
6
- exports.NewRetryPolicyFactory = NewRetryPolicyFactory;
7
- const abort_controller_1 = require("@azure/abort-controller");
8
- const storage_blob_1 = require("@azure/storage-blob");
9
- const constants_js_1 = require("../utils/constants.js");
10
- const utils_common_js_1 = require("../utils/utils.common.js");
11
- const log_js_1 = require("../log.js");
12
- /**
13
- * A factory method used to generated a RetryPolicy factory.
14
- *
15
- * @param retryOptions -
16
- */
17
- function NewRetryPolicyFactory(retryOptions) {
18
- return {
19
- create: (nextPolicy, options) => {
20
- return new StorageRetryPolicy(nextPolicy, options, retryOptions);
21
- },
22
- };
23
- }
24
- /**
25
- * RetryPolicy types.
26
- */
27
- var StorageRetryPolicyType;
28
- (function (StorageRetryPolicyType) {
29
- /**
30
- * Exponential retry. Retry time delay grows exponentially.
31
- */
32
- StorageRetryPolicyType[StorageRetryPolicyType["EXPONENTIAL"] = 0] = "EXPONENTIAL";
33
- /**
34
- * Linear retry. Retry time delay grows linearly.
35
- */
36
- StorageRetryPolicyType[StorageRetryPolicyType["FIXED"] = 1] = "FIXED";
37
- })(StorageRetryPolicyType || (exports.StorageRetryPolicyType = StorageRetryPolicyType = {}));
38
- // Default values of StorageRetryOptions
39
- const DEFAULT_RETRY_OPTIONS = {
40
- maxRetryDelayInMs: 120 * 1000,
41
- maxTries: 4,
42
- retryDelayInMs: 4 * 1000,
43
- retryPolicyType: StorageRetryPolicyType.EXPONENTIAL,
44
- tryTimeoutInMs: undefined, // Use server side default timeout strategy
45
- };
46
- const RETRY_ABORT_ERROR = new abort_controller_1.AbortError("The operation was aborted.");
47
- /**
48
- * Retry policy with exponential retry and linear retry implemented.
49
- */
50
- class StorageRetryPolicy extends storage_blob_1.BaseRequestPolicy {
51
- /**
52
- * Creates an instance of RetryPolicy.
53
- *
54
- * @param nextPolicy -
55
- * @param options -
56
- * @param retryOptions -
57
- */
58
- constructor(nextPolicy, options, retryOptions = DEFAULT_RETRY_OPTIONS) {
59
- super(nextPolicy, options);
60
- // Initialize retry options
61
- this.retryOptions = {
62
- retryPolicyType: retryOptions.retryPolicyType
63
- ? retryOptions.retryPolicyType
64
- : DEFAULT_RETRY_OPTIONS.retryPolicyType,
65
- maxTries: retryOptions.maxTries && retryOptions.maxTries >= 1
66
- ? Math.floor(retryOptions.maxTries)
67
- : DEFAULT_RETRY_OPTIONS.maxTries,
68
- tryTimeoutInMs: retryOptions.tryTimeoutInMs && retryOptions.tryTimeoutInMs >= 0
69
- ? retryOptions.tryTimeoutInMs
70
- : DEFAULT_RETRY_OPTIONS.tryTimeoutInMs,
71
- retryDelayInMs: retryOptions.retryDelayInMs && retryOptions.retryDelayInMs >= 0
72
- ? Math.min(retryOptions.retryDelayInMs, retryOptions.maxRetryDelayInMs
73
- ? retryOptions.maxRetryDelayInMs
74
- : DEFAULT_RETRY_OPTIONS.maxRetryDelayInMs)
75
- : DEFAULT_RETRY_OPTIONS.retryDelayInMs,
76
- maxRetryDelayInMs: retryOptions.maxRetryDelayInMs && retryOptions.maxRetryDelayInMs >= 0
77
- ? retryOptions.maxRetryDelayInMs
78
- : DEFAULT_RETRY_OPTIONS.maxRetryDelayInMs,
79
- };
80
- }
81
- /**
82
- * Sends request.
83
- *
84
- * @param request -
85
- */
86
- async sendRequest(request) {
87
- return this.attemptSendRequest(request, false, 1);
88
- }
89
- /**
90
- * Decide and perform next retry. Won't mutate request parameter.
91
- *
92
- * @param request -
93
- * @param secondaryHas404 - If attempt was against the secondary & it returned a StatusNotFound (404), then
94
- * the resource was not found. This may be due to replication delay. So, in this
95
- * case, we'll never try the secondary again for this operation.
96
- * @param attempt - How many retries has been attempted to performed, starting from 1, which includes
97
- * the attempt will be performed by this method call.
98
- */
99
- async attemptSendRequest(request, secondaryHas404, attempt) {
100
- const newRequest = request.clone();
101
- const isPrimaryRetry = true;
102
- // Set the server-side timeout query parameter "timeout=[seconds]"
103
- if (this.retryOptions.tryTimeoutInMs) {
104
- newRequest.url = (0, utils_common_js_1.setURLParameter)(newRequest.url, constants_js_1.URLConstants.Parameters.TIMEOUT, Math.floor(this.retryOptions.tryTimeoutInMs / 1000).toString());
105
- }
106
- let response;
107
- try {
108
- log_js_1.logger.info(`RetryPolicy: =====> Try=${attempt} ${isPrimaryRetry ? "Primary" : "Secondary"}`);
109
- response = await this._nextPolicy.sendRequest(newRequest);
110
- if (!this.shouldRetry(isPrimaryRetry, attempt, response)) {
111
- return response;
112
- }
113
- secondaryHas404 = secondaryHas404 || (!isPrimaryRetry && response.status === 404);
114
- }
115
- catch (err) {
116
- log_js_1.logger.error(`RetryPolicy: Caught error, message: ${err.message}, code: ${err.code}`);
117
- if (!this.shouldRetry(isPrimaryRetry, attempt, response, err)) {
118
- throw err;
119
- }
120
- }
121
- await this.delay(isPrimaryRetry, attempt, request.abortSignal);
122
- return this.attemptSendRequest(request, secondaryHas404, ++attempt);
123
- }
124
- /**
125
- * Decide whether to retry according to last HTTP response and retry counters.
126
- *
127
- * @param isPrimaryRetry -
128
- * @param attempt -
129
- * @param response -
130
- * @param err -
131
- */
132
- shouldRetry(isPrimaryRetry, attempt, response, err) {
133
- if (attempt >= this.retryOptions.maxTries) {
134
- log_js_1.logger.info(`RetryPolicy: Attempt(s) ${attempt} >= maxTries ${this.retryOptions
135
- .maxTries}, no further try.`);
136
- return false;
137
- }
138
- // Handle network failures, you may need to customize the list when you implement
139
- // your own http client
140
- const retriableErrors = [
141
- "ETIMEDOUT",
142
- "ESOCKETTIMEDOUT",
143
- "ECONNREFUSED",
144
- "ECONNRESET",
145
- "ENOENT",
146
- "ENOTFOUND",
147
- "TIMEOUT",
148
- "EPIPE",
149
- "REQUEST_SEND_ERROR", // For default xhr based http client provided in ms-rest-js
150
- ];
151
- if (err) {
152
- for (const retriableError of retriableErrors) {
153
- if (err.name.toUpperCase().includes(retriableError) ||
154
- err.message.toUpperCase().includes(retriableError) ||
155
- (err.code && err.code.toString().toUpperCase() === retriableError)) {
156
- log_js_1.logger.info(`RetryPolicy: Network error ${retriableError} found, will retry.`);
157
- return true;
158
- }
159
- }
160
- }
161
- // If attempt was against the secondary & it returned a StatusNotFound (404), then
162
- // the resource was not found. This may be due to replication delay. So, in this
163
- // case, we'll never try the secondary again for this operation.
164
- if (response || err) {
165
- const statusCode = response ? response.status : err ? err.statusCode : 0;
166
- if (!isPrimaryRetry && statusCode === 404) {
167
- log_js_1.logger.info(`RetryPolicy: Secondary access with 404, will retry.`);
168
- return true;
169
- }
170
- // Server internal error or server timeout
171
- if (statusCode === 503 || statusCode === 500) {
172
- log_js_1.logger.info(`RetryPolicy: Will retry for status code ${statusCode}.`);
173
- return true;
174
- }
175
- }
176
- // [Copy source error code] Feature is pending on service side, skip retry on copy source error for now.
177
- // if (response) {
178
- // // Retry select Copy Source Error Codes.
179
- // if (response?.status >= 400) {
180
- // const copySourceError = response.headers.get(HeaderConstants.X_MS_CopySourceErrorCode);
181
- // if (copySourceError !== undefined) {
182
- // switch (copySourceError)
183
- // {
184
- // case "InternalError":
185
- // case "OperationTimedOut":
186
- // case "ServerBusy":
187
- // return true;
188
- // }
189
- // }
190
- // }
191
- // }
192
- if ((err === null || err === void 0 ? void 0 : err.code) === "PARSE_ERROR" && (err === null || err === void 0 ? void 0 : err.message.startsWith(`Error "Error: Unclosed root tag`))) {
193
- log_js_1.logger.info("RetryPolicy: Incomplete XML response likely due to service timeout, will retry.");
194
- return true;
195
- }
196
- return false;
197
- }
198
- /**
199
- * Delay a calculated time between retries.
200
- *
201
- * @param isPrimaryRetry -
202
- * @param attempt -
203
- * @param abortSignal -
204
- */
205
- async delay(isPrimaryRetry, attempt, abortSignal) {
206
- let delayTimeInMs = 0;
207
- if (isPrimaryRetry) {
208
- switch (this.retryOptions.retryPolicyType) {
209
- case StorageRetryPolicyType.EXPONENTIAL:
210
- delayTimeInMs = Math.min((Math.pow(2, attempt - 1) - 1) * this.retryOptions.retryDelayInMs, this.retryOptions.maxRetryDelayInMs);
211
- break;
212
- case StorageRetryPolicyType.FIXED:
213
- delayTimeInMs = this.retryOptions.retryDelayInMs;
214
- break;
215
- }
216
- }
217
- else {
218
- delayTimeInMs = Math.random() * 1000;
219
- }
220
- log_js_1.logger.info(`RetryPolicy: Delay for ${delayTimeInMs}ms`);
221
- return (0, utils_common_js_1.delay)(delayTimeInMs, abortSignal, RETRY_ABORT_ERROR);
222
- }
223
- }
224
- exports.StorageRetryPolicy = StorageRetryPolicy;
225
- //# sourceMappingURL=StorageRetryPolicy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StorageRetryPolicy.js","sourceRoot":"","sources":["../../../src/policies/StorageRetryPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAwBlC,sDAMC;AA3BD,8DAAqD;AAQrD,sDAAwD;AAIxD,wDAAqD;AACrD,8DAAkE;AAClE,sCAAmC;AAEnC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,CAAC,CAAC;QACzD,OAAO,IAAA,uBAAK,EAAC,aAAa,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;IAC9D,CAAC;CACF;AA3OD,gDA2OC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { AbortError } from \"@azure/abort-controller\";\nimport type {\n RequestPolicy,\n RequestPolicyOptionsLike as RequestPolicyOptions,\n RequestPolicyFactory,\n WebResourceLike as WebResource,\n CompatResponse as HttpOperationResponse,\n} from \"@azure/core-http-compat\";\nimport { BaseRequestPolicy } from \"@azure/storage-blob\";\nimport type { RestError } from \"@azure/core-rest-pipeline\";\n\nimport type { StorageRetryOptions } from \"../StorageRetryPolicyFactory.js\";\nimport { URLConstants } from \"../utils/constants.js\";\nimport { delay, setURLParameter } from \"../utils/utils.common.js\";\nimport { logger } from \"../log.js\";\n\n/**\n * A factory method used to generated a RetryPolicy factory.\n *\n * @param retryOptions -\n */\nexport function NewRetryPolicyFactory(retryOptions?: StorageRetryOptions): RequestPolicyFactory {\n return {\n create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions): StorageRetryPolicy => {\n return new StorageRetryPolicy(nextPolicy, options, retryOptions);\n },\n };\n}\n\n/**\n * RetryPolicy types.\n */\nexport enum StorageRetryPolicyType {\n /**\n * Exponential retry. Retry time delay grows exponentially.\n */\n EXPONENTIAL,\n /**\n * Linear retry. Retry time delay grows linearly.\n */\n FIXED,\n}\n\n// Default values of StorageRetryOptions\nconst DEFAULT_RETRY_OPTIONS: StorageRetryOptions = {\n maxRetryDelayInMs: 120 * 1000,\n maxTries: 4,\n retryDelayInMs: 4 * 1000,\n retryPolicyType: StorageRetryPolicyType.EXPONENTIAL,\n tryTimeoutInMs: undefined, // Use server side default timeout strategy\n};\n\nconst RETRY_ABORT_ERROR = new AbortError(\"The operation was aborted.\");\n\n/**\n * Retry policy with exponential retry and linear retry implemented.\n */\nexport class StorageRetryPolicy extends BaseRequestPolicy {\n /**\n * RetryOptions.\n */\n private readonly retryOptions: StorageRetryOptions;\n\n /**\n * Creates an instance of RetryPolicy.\n *\n * @param nextPolicy -\n * @param options -\n * @param retryOptions -\n */\n constructor(\n nextPolicy: RequestPolicy,\n options: RequestPolicyOptions,\n retryOptions: StorageRetryOptions = DEFAULT_RETRY_OPTIONS,\n ) {\n super(nextPolicy, options);\n\n // Initialize retry options\n this.retryOptions = {\n retryPolicyType: retryOptions.retryPolicyType\n ? retryOptions.retryPolicyType\n : DEFAULT_RETRY_OPTIONS.retryPolicyType,\n\n maxTries:\n retryOptions.maxTries && retryOptions.maxTries >= 1\n ? Math.floor(retryOptions.maxTries)\n : DEFAULT_RETRY_OPTIONS.maxTries,\n\n tryTimeoutInMs:\n retryOptions.tryTimeoutInMs && retryOptions.tryTimeoutInMs >= 0\n ? retryOptions.tryTimeoutInMs\n : DEFAULT_RETRY_OPTIONS.tryTimeoutInMs,\n\n retryDelayInMs:\n retryOptions.retryDelayInMs && retryOptions.retryDelayInMs >= 0\n ? Math.min(\n retryOptions.retryDelayInMs,\n retryOptions.maxRetryDelayInMs\n ? retryOptions.maxRetryDelayInMs\n : DEFAULT_RETRY_OPTIONS.maxRetryDelayInMs!,\n )\n : DEFAULT_RETRY_OPTIONS.retryDelayInMs,\n\n maxRetryDelayInMs:\n retryOptions.maxRetryDelayInMs && retryOptions.maxRetryDelayInMs >= 0\n ? retryOptions.maxRetryDelayInMs\n : DEFAULT_RETRY_OPTIONS.maxRetryDelayInMs,\n };\n }\n\n /**\n * Sends request.\n *\n * @param request -\n */\n public async sendRequest(request: WebResource): Promise<HttpOperationResponse> {\n return this.attemptSendRequest(request, false, 1);\n }\n\n /**\n * Decide and perform next retry. Won't mutate request parameter.\n *\n * @param request -\n * @param secondaryHas404 - If attempt was against the secondary & it returned a StatusNotFound (404), then\n * the resource was not found. This may be due to replication delay. So, in this\n * case, we'll never try the secondary again for this operation.\n * @param attempt - How many retries has been attempted to performed, starting from 1, which includes\n * the attempt will be performed by this method call.\n */\n protected async attemptSendRequest(\n request: WebResource,\n secondaryHas404: boolean,\n attempt: number,\n ): Promise<HttpOperationResponse> {\n const newRequest: WebResource = request.clone();\n\n const isPrimaryRetry = true;\n\n // Set the server-side timeout query parameter \"timeout=[seconds]\"\n if (this.retryOptions.tryTimeoutInMs) {\n newRequest.url = setURLParameter(\n newRequest.url,\n URLConstants.Parameters.TIMEOUT,\n Math.floor(this.retryOptions.tryTimeoutInMs! / 1000).toString(),\n );\n }\n\n let response: HttpOperationResponse | undefined;\n try {\n logger.info(`RetryPolicy: =====> Try=${attempt} ${isPrimaryRetry ? \"Primary\" : \"Secondary\"}`);\n response = await this._nextPolicy.sendRequest(newRequest);\n if (!this.shouldRetry(isPrimaryRetry, attempt, response)) {\n return response;\n }\n\n secondaryHas404 = secondaryHas404 || (!isPrimaryRetry && response.status === 404);\n } catch (err: any) {\n logger.error(`RetryPolicy: Caught error, message: ${err.message}, code: ${err.code}`);\n if (!this.shouldRetry(isPrimaryRetry, attempt, response, err)) {\n throw err;\n }\n }\n\n await this.delay(isPrimaryRetry, attempt, request.abortSignal);\n return this.attemptSendRequest(request, secondaryHas404, ++attempt);\n }\n\n /**\n * Decide whether to retry according to last HTTP response and retry counters.\n *\n * @param isPrimaryRetry -\n * @param attempt -\n * @param response -\n * @param err -\n */\n protected shouldRetry(\n isPrimaryRetry: boolean,\n attempt: number,\n response?: HttpOperationResponse,\n err?: RestError,\n ): boolean {\n if (attempt >= this.retryOptions.maxTries!) {\n logger.info(\n `RetryPolicy: Attempt(s) ${attempt} >= maxTries ${this.retryOptions\n .maxTries!}, no further try.`,\n );\n return false;\n }\n\n // Handle network failures, you may need to customize the list when you implement\n // your own http client\n const retriableErrors = [\n \"ETIMEDOUT\",\n \"ESOCKETTIMEDOUT\",\n \"ECONNREFUSED\",\n \"ECONNRESET\",\n \"ENOENT\",\n \"ENOTFOUND\",\n \"TIMEOUT\",\n \"EPIPE\",\n \"REQUEST_SEND_ERROR\", // For default xhr based http client provided in ms-rest-js\n ];\n if (err) {\n for (const retriableError of retriableErrors) {\n if (\n err.name.toUpperCase().includes(retriableError) ||\n err.message.toUpperCase().includes(retriableError) ||\n (err.code && err.code.toString().toUpperCase() === retriableError)\n ) {\n logger.info(`RetryPolicy: Network error ${retriableError} found, will retry.`);\n return true;\n }\n }\n }\n\n // If attempt was against the secondary & it returned a StatusNotFound (404), then\n // the resource was not found. This may be due to replication delay. So, in this\n // case, we'll never try the secondary again for this operation.\n if (response || err) {\n const statusCode = response ? response.status : err ? err.statusCode : 0;\n if (!isPrimaryRetry && statusCode === 404) {\n logger.info(`RetryPolicy: Secondary access with 404, will retry.`);\n return true;\n }\n\n // Server internal error or server timeout\n if (statusCode === 503 || statusCode === 500) {\n logger.info(`RetryPolicy: Will retry for status code ${statusCode}.`);\n return true;\n }\n }\n\n // [Copy source error code] Feature is pending on service side, skip retry on copy source error for now.\n // if (response) {\n // // Retry select Copy Source Error Codes.\n // if (response?.status >= 400) {\n // const copySourceError = response.headers.get(HeaderConstants.X_MS_CopySourceErrorCode);\n // if (copySourceError !== undefined) {\n // switch (copySourceError)\n // {\n // case \"InternalError\":\n // case \"OperationTimedOut\":\n // case \"ServerBusy\":\n // return true;\n // }\n // }\n // }\n // }\n\n if (err?.code === \"PARSE_ERROR\" && err?.message.startsWith(`Error \"Error: Unclosed root tag`)) {\n logger.info(\n \"RetryPolicy: Incomplete XML response likely due to service timeout, will retry.\",\n );\n return true;\n }\n\n return false;\n }\n\n /**\n * Delay a calculated time between retries.\n *\n * @param isPrimaryRetry -\n * @param attempt -\n * @param abortSignal -\n */\n private async delay(\n isPrimaryRetry: boolean,\n attempt: number,\n abortSignal?: AbortSignalLike,\n ): Promise<void> {\n let delayTimeInMs: number = 0;\n\n if (isPrimaryRetry) {\n switch (this.retryOptions.retryPolicyType) {\n case StorageRetryPolicyType.EXPONENTIAL:\n delayTimeInMs = Math.min(\n (Math.pow(2, attempt - 1) - 1) * this.retryOptions.retryDelayInMs!,\n this.retryOptions.maxRetryDelayInMs!,\n );\n break;\n case StorageRetryPolicyType.FIXED:\n delayTimeInMs = this.retryOptions.retryDelayInMs!;\n break;\n }\n } else {\n delayTimeInMs = Math.random() * 1000;\n }\n\n logger.info(`RetryPolicy: Delay for ${delayTimeInMs}ms`);\n return delay(delayTimeInMs, abortSignal, RETRY_ABORT_ERROR);\n }\n}\n"]}