Skip to content

Use a monotonic clock for calibration - #301

Open
OskarEichler wants to merge 1 commit into
bcrypt-ruby:masterfrom
OskarEichler:codex/use-monotonic-calibration
Open

OskarEichler wants to merge 1 commit into
bcrypt-ruby:masterfrom
OskarEichler:codex/use-monotonic-calibration

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Measure BCrypt::Engine.calibrate with Ruby's monotonic process clock instead of the adjustable wall clock.

This keeps elapsed-time measurements stable when NTP, virtualization, or an administrator moves the system clock while calibration is running, and addresses the timing fragility discussed in #235 and #248.

Reproduction

An external focused model replaces Time.now with a method that raises. The current implementation raises from calibrate; this branch returns MIN_COST for a tiny time budget because calibration no longer consults wall time.

Verification

  • bundle exec rake compile spec: 39 examples, 0 failures on Ruby 4.0.6
  • focused wall-clock-isolation model: pass

Compatibility

No public API, cost selection algorithm, or supported platform changes. Process.clock_gettime(Process::CLOCK_MONOTONIC) is available on the supported Ruby versions.

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