Skip to content

Commit

Permalink
fix: ensure lease is rechecked during each retry attempt
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Klick <[email protected]>
  • Loading branch information
nathanklick committed Nov 13, 2024
1 parent b111614 commit 05871be
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class MirrorNodeCommand extends BaseCommand {
async prepareHederaExplorerValuesArg (config: any) {
let valuesArg = ''

const profileName = <string>this.configManager.getFlag<string>(flags.profileName)
const profileName = this.configManager.getFlag<string>(flags.profileName) as string
const profileValuesFile = await this.profileManager.prepareValuesHederaExplorerChart(profileName)
if (profileValuesFile) {
valuesArg += this.prepareValuesFiles(profileValuesFile)
Expand Down
2 changes: 1 addition & 1 deletion src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const MINUTES = 60 * SECONDS

export const LEASE_ACQUIRE_RETRY_TIMEOUT = +process.env.LEASE_ACQUIRE_RETRY_TIMEOUT || 20 * SECONDS
export const MAX_LEASE_ACQUIRE_ATTEMPTS = +process.env.MAX_LEASE_ACQUIRE_ATTEMPTS || 10
export const LEASE_RENEW_TIMEOUT = +process.env.LEASE_RENEW_TIMEOUT || 10 * SECONDS
export const DEFAULT_LEASE_RENEW_TIMEOUT = 10 * SECONDS

export const PODS_RUNNING_MAX_ATTEMPTS = +process.env.PODS_RUNNING_MAX_ATTEMPTS || 60 * 15
export const PODS_RUNNING_DELAY = +process.env.PODS_RUNNING_DELAY || 1000
Expand Down
8 changes: 5 additions & 3 deletions src/core/lease_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { flags } from '../commands/index.ts'
import type { ConfigManager } from './config_manager.ts'
import type { K8 } from './k8.ts'
import type { SoloLogger } from './logging.ts'
import { LEASE_RENEW_TIMEOUT, LEASE_ACQUIRE_RETRY_TIMEOUT, MAX_LEASE_ACQUIRE_ATTEMPTS, OS_USERNAME } from './constants.ts'
import { DEFAULT_LEASE_RENEW_TIMEOUT, LEASE_ACQUIRE_RETRY_TIMEOUT, MAX_LEASE_ACQUIRE_ATTEMPTS, OS_USERNAME } from './constants.ts'
import type { ListrTaskWrapper } from 'listr2'
import chalk from 'chalk'
import { sleep } from './helpers.ts'
Expand Down Expand Up @@ -77,7 +77,8 @@ export class LeaseManager {
}

//? Renew lease with the callback
const intervalId = setInterval(renewLeaseCallback, LEASE_RENEW_TIMEOUT)
const renewalTimeout = +process.env.LEASE_RENEW_TIMEOUT || DEFAULT_LEASE_RENEW_TIMEOUT
const intervalId = setInterval(renewLeaseCallback, renewalTimeout)

const releaseLeaseCallback = async () => {
//? Stop renewing the lease once release callback is called
Expand Down Expand Up @@ -121,7 +122,7 @@ export class LeaseManager {
): Promise<void> {
if (!attempt) attempt = 1

const lease = await this.tryAcquireLease(username, leaseName, namespace, task, title)
let lease = await this.tryAcquireLease(username, leaseName, namespace, task, title)

//? In case the lease is already acquired retry after cooldown
while (!!lease && !this.isLeaseExpired(lease)) {
Expand All @@ -140,6 +141,7 @@ export class LeaseManager {
`, attempt: ${chalk.cyan(attempt.toString())}/${chalk.cyan(maxAttempts.toString())}`

await sleep(LEASE_ACQUIRE_RETRY_TIMEOUT)
lease = await this.tryAcquireLease(username, leaseName, namespace, task, title)
}

if (lease) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DataValidationError, SoloError, IllegalArgumentError, MissingArgumentEr
import { constants } from './index.ts'
import { type AccountId } from '@hashgraph/sdk'
import type { NodeAlias, PodName } from '../types/aliases.ts'
import { GrpcProxyTlsEnums} from './enumerations.ts'
import { GrpcProxyTlsEnums } from './enumerations.ts'

export class Templates {
public static renderNetworkPodName (nodeAlias: NodeAlias): PodName {
Expand Down
11 changes: 9 additions & 2 deletions test/e2e/integration/core/lease_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import { expect } from 'chai'
import { flags } from '../../../../src/commands/index.ts'
import { e2eTestSuite, getDefaultArgv, TEST_CLUSTER } from '../../../test_util.ts'
import * as version from '../../../../version.ts'
import { LEASE_ACQUIRE_RETRY_TIMEOUT, MAX_LEASE_ACQUIRE_ATTEMPTS, MINUTES } from '../../../../src/core/constants.ts'
import {
DEFAULT_LEASE_RENEW_TIMEOUT,
LEASE_ACQUIRE_RETRY_TIMEOUT,
MAX_LEASE_ACQUIRE_ATTEMPTS,
MINUTES
} from '../../../../src/core/constants.ts'
import { sleep } from '../../../../src/core/helpers.js'

const namespace = 'lease-mngr-e2e'
Expand Down Expand Up @@ -77,14 +82,16 @@ e2eTestSuite(namespace, argv, undefined, undefined, undefined, undefined, undefi
}).timeout(3 * MINUTES)

it('expired leases should be overwritten', async () => {
process.env.LEASE_RENEW_TIMEOUT = (DEFAULT_LEASE_RENEW_TIMEOUT * 4).toString()
const initialLease = leaseManager.instantiateLease()
const title = 'Initial Lease'
// @ts-ignore to access private property
await initialLease.acquireTask({ title }, title)

// Ensure lease expires
await sleep(LEASE_ACQUIRE_RETRY_TIMEOUT * 1.5)
await sleep(LEASE_ACQUIRE_RETRY_TIMEOUT)

process.env.LEASE_RENEW_TIMEOUT = DEFAULT_LEASE_RENEW_TIMEOUT.toString()
const newLease = leaseManager.instantiateLease()
const newTitle = 'New Lease'
// @ts-ignore to access private property
Expand Down

0 comments on commit 05871be

Please sign in to comment.