Skip to content

improve lease code - #911

Open
pjfanning wants to merge 9 commits into
apache:mainfrom
pjfanning:lease
Open

improve lease code#911
pjfanning wants to merge 9 commits into
apache:mainfrom
pjfanning:lease

Conversation

@pjfanning

@pjfanning pjfanning commented Jul 30, 2026

Copy link
Copy Markdown
Member

H9. Premature LeaseAcquired Reply Before Lease Is Granted

File: lease-kubernetes/.../LeaseActor.scala:172-177

On conflict retry, LeaseAcquired is sent to the caller before the retry update succeeds. granted.set(true) is never called.

H10. No Heartbeat Retry — Immediate Lease Loss on Transient Failure

File: lease-kubernetes/.../LeaseActor.scala:201-206

A single heartbeat failure immediately releases the lease (with 120s TTL budget available for retries). Contains a FIXME acknowledging this.

M9 — Connection leak on timeout: Replaced Future.firstCompletedOf with a Promise-based approach. Both the response and timeout write to the same promise via trySuccess/tryFailure. When the timeout fires first, it calls response.foreach(_.discardEntityBytes()) to consume the response entity if one arrives later, preventing the HTTP connection from leaking. The promise-based approach avoids the race condition where firstCompletedOf abandons the slower future without cleanup.

L6 — DateTimeFormatter on every heartbeat: Added UTC_FORMATTER as a val in the companion object (NativeKubernetesApiImpl.scala:43) that caches RFC3339MICRO_FORMATTER.withZone(ZoneId.of("UTC")). The currentTimeRFC3339 method now uses this cached formatter instead of calling .withZone on every heartbeat.

L7 — Silent Acquire drop: In LeaseActor.scala:247, the whenUnhandled Acquire handler now sends InvalidRequest("Tried to acquire a lease while previous acquire/release still in progress") to the sender, matching the behavior of the Release handler. Previously it logged but never replied, leaving the caller hanging.

Also deals with: FIXME deal with failure from releasing the the lock, currently handled in whenUnhandled but could retry to remove

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant