Sample nxf_date seconds and nanoseconds atomically#7207
Merged
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Paolo Di Tommaso <[email protected]>
✅ Deploy Preview for nextflow-docs-staging canceled.
|
Collaborator
|
Great catch! |
bentsherman
approved these changes
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #7118. That PR fixed
nxf_datefor uutils coreutils, but in doing so it replaced the singledate +%s%3Ninvocation with two separate calls:This reintroduces a subtle timing bug. The two
dateprocesses are sampled at slightly different instants, so a second boundary can fall between them:%sis read in second K, then%Nis read just after the tick into second K+1, when the nanosecond fraction has reset to near zero. The result is a timestamp that is up to ~1000 ms behind the true time.nxf_dateis used to record task start/complete times for trace metrics. Because the skew only ever under-estimates (seconds are read first and can only lag), adelta = end - startwhere theendcall straddles a boundary can come out smaller than the real duration — and for very short tasks, even slightly negative. The original single-call implementation sampled both fields atomically and never had this problem.Change
Read both fields from a single
dateinvocation so they cannot straddle a second boundary:All the platform-handling logic introduced in #7118 is preserved unchanged:
%N, used directly.%N; re-padded to 9 digits viaprintf '%09d'so the millisecond extraction stays correct.%Nyields a non-numeric literal (N); the regex check falls back to second precision.date '+%s %N'is a singlestrftime/fork, supported identically wherever the per-field calls were, so there is no new portability cost — only the loss of the inter-call gap.Test plan
:nextflow:test --tests BashWrapperBuilderTestpasses after updating both wrapper fixtures (test-bash-wrapper.txt,test-bash-wrapper-with-trace.txt)🤖 Generated with Claude Code