Skip to content

Replace timeoutMs: Long with timeout: Duration across the timeout API#9

Open
rusio wants to merge 2 commits intoanschnapp:masterfrom
rusio:feature/time-units
Open

Replace timeoutMs: Long with timeout: Duration across the timeout API#9
rusio wants to merge 2 commits intoanschnapp:masterfrom
rusio:feature/time-units

Conversation

@rusio
Copy link
Copy Markdown

@rusio rusio commented Mar 31, 2026

Using Duration removes the millisecond unit assumption, eliminates the nanos conversion factor, and lets Session.isExpired() carry its own logic cleanly. Deadline storage moves from a sentinel long (0 = none) to a nullable Instant, making the absent-deadline case explicit. Adds SessionTimeoutTest covering the key timeout scenarios.

Rusi Filipov and others added 2 commits March 31, 2026 22:36
… API

Using Duration removes the millisecond unit assumption, eliminates the
nanos conversion factor, and lets Session.isExpired() carry its own
logic cleanly. Deadline storage moves from a sentinel long (0 = none)
to a nullable Instant, making the absent-deadline case explicit.
Adds SessionTimeoutTest covering the key timeout scenarios.
includeTargets: List<String> = emptyList(),
excludeTargets: List<String> = emptyList(),
timeoutMs: Long = 60_000,
timeout: Duration = Duration.ofMinutes(1)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma is missing after this argument, so the build fails.

i guess this was coming in when you merged from master (so some kind of merge issue)

i'm also not sure if this is the only one issue of this kind.
to make it more easy to check for those errors i have now a tiny CI pipeline.
so after you have fixed it please pull from master again, then you get the pipeline on our next push and it build and tests will be checked within the github UI

} else 0L
currentSession = Session(activeMutation, deadlineNanos = deadlineNanos)
val deadline = if (activeMutation != null && timeout != null) {
Instant.now() + timeout
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code used System.nanoTime() which is monotonic -- it only moves forward, regardless of what happens to the system clock.

Here you use Instant.now() which reads the wall clock and can jump backward or forward due to NTP sync, clock adjustments etc...

For a timeout that detects infinite loops in mutation runs:

  • Clock jumps forward -> false timeout, a healthy mutation gets killed prematurely
  • Clock jumps backward -> missed timeout, an actual infinite loop runs longer than expected (or never triggers)

I would say let's keep the Duration as the public API type (that's a good improvement), but internally still convert to a System.nanoTime()-based deadline for the actual expiry check.

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.

2 participants