Skip to content

Commit

Permalink
fix(hana): reduce service manager calls for failing tenants (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobdenOs authored Mar 20, 2024
1 parent eb9beda commit e95fd17
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ class HANAService extends SQLService {
const driver = drivers[this.options.driver || this.options.credentials?.driver]?.driver || drivers.default.driver
const isMultitenant = 'multiTenant' in this.options ? this.options.multiTenant : cds.env.requires.multitenancy
const service = this
const acquireTimeoutMillis = this.options.pool?.acquireTimeoutMillis || cds.env.profiles.includes('production') ? 1000 : 10000
return {
options: {
min: 0,
max: 10,
acquireTimeoutMillis: cds.env.profiles.includes('production') ? 1000 : 10000,
acquireTimeoutMillis,
idleTimeoutMillis: 60000,
evictionRunIntervalMillis: 100000,
numTestsPerEvictionRun: Math.ceil((this.options.pool?.max || 10) - (this.options.pool?.min || 0) / 3),
Expand All @@ -60,7 +61,14 @@ class HANAService extends SQLService {
HANAVERSION = dbc.server.major
return dbc
} catch (err) {
if (!isMultitenant || err.code !== 10) throw err
if (isMultitenant) {
// REVISIT: throw the error and break retry loop
// Stop trying when the tenant does not exist or is rate limited
if (err.status == 404 || err.status == 429)
return new Promise(function (_, reject) {
setTimeout(() => reject(err), acquireTimeoutMillis)
})
} else if (err.code !== 10) throw err
await require('@sap/cds-mtxs/lib').xt.serviceManager.get(tenant, { disableCache: true })
return this.create(tenant)
}
Expand Down

0 comments on commit e95fd17

Please sign in to comment.