Skip to content

fix bug in retry while error handling #1392

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

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
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
24 changes: 17 additions & 7 deletions src/internal/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,34 @@ export async function requestWithRetry(
maxRetries: number = MAX_RETRIES,
): Promise<http.IncomingMessage> {
let attempt = 0
let isRetryable = false
while (attempt <= maxRetries) {
try {
const response = await request(transport, opt, body)
// Check if the HTTP status code is retryable
if (isHttpRetryable(response.statusCode as number)) {
isRetryable = true
throw new Error(`Retryable HTTP status: ${response.statusCode}`) // trigger retry attempt with calculated delay
}

return response // Success, return the raw response
} catch (err) {
attempt++
if (isRetryable) {
attempt++
isRetryable = false

if (attempt > maxRetries) {
throw new Error(`Request failed after ${maxRetries} retries: ${err}`)
if (attempt > maxRetries) {
throw new Error(`Request failed after ${maxRetries} retries: ${err}`)
}
const delay = getExpBackOffDelay(attempt)
// eslint-disable-next-line no-console
console.warn(
`${new Date().toLocaleString()} Retrying request (attempt ${attempt}/${maxRetries}) after ${delay}ms due to: ${err}`,
)
await sleep(delay)
} else {
throw err // re-throw if any request, syntax errors
}
const delay = getExpBackOffDelay(attempt)
// eslint-disable-next-line no-console
// console.warn( `${new Date().toLocaleString()} Retrying request (attempt ${attempt}/${maxRetries}) after ${delay}ms due to: ${err}`,)
await sleep(delay)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/functional-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
const isWindowsPlatform = process.platform === 'win32'

describe('functional tests', function () {
this.timeout(300000) // 5 minutes
this.timeout(30 * 60 * 1000)
var clientConfigParams = {}
var region_conf_env = process.env['MINIO_REGION']

Expand Down Expand Up @@ -3629,13 +3629,13 @@
const metadata = { 'X-Amz-Meta-Test': 'test-value' }

before(() => {
return client.makeBucket(bucketName, '').then((res) => {

Check warning on line 3632 in tests/functional/functional-tests.js

View workflow job for this annotation

GitHub Actions / lint

'res' is defined but never used
return client.putObject(bucketName, objectName, fdObject, fdObject.length, metadata).then((res) => {

Check warning on line 3633 in tests/functional/functional-tests.js

View workflow job for this annotation

GitHub Actions / lint

'res' is defined but never used
return client.setObjectTagging(bucketName, objectName, tags)
})
})
})
after(() => client.removeObject(bucketName, objectName).then((_) => client.removeBucket(bucketName)))

Check warning on line 3638 in tests/functional/functional-tests.js

View workflow job for this annotation

GitHub Actions / lint

'_' is defined but never used

step(
`extensions.listObjectsV2WithMetadata(bucketName, prefix, recursive)_bucketName:${bucketName}, prefix:"", recursive:true`,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ describe('CopyConditions', () => {

describe('Client', function () {
var nockRequests = []
this.timeout(300000) // 5 minutes
this.timeout(5000) // 5 minutes
beforeEach(() => {
Nock.cleanAll()
nockRequests = []
Expand Down
Loading