[iOS] JS timers fire late by the size of a backward system clock change
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 53/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- ios, objective-c, react-native, typescript
Hướng nghiên cứu
Start with packages/react-native/React/CoreModules/RCTTiming.mm, especially the timer target calculations and sleep NSTimer setup at the cited lines; compare how JavaTimerManager uses monotonic time. The issue also identifies ObjCTimerRegistry.mm and RCTInstance.mm as the bridgeless path. Determine how iOS timers should respond to system clock changes while preserving sleep time, then verify both timeout and interval behavior with the supplied device reproducer.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
On iOS, when the system clock steps back by D, every pending setTimeout and setInterval fires D late. A forward step makes them fire up to D early. Android is not affected. The clock steps when automatic time corrects a clock that ran fast, or when the user sets the time by hand.
RCTTiming stores each timer's target as a wall-clock date, [NSDate dateWithTimeIntervalSinceNow:] (RCTTiming.mm:49, and :68 for intervals), and fires it once [NSDate date] reaches that date (:57-63, :246). For a target more than a second away, it pauses the display link and arms a sleep NSTimer for the same date (:311-313, :318-333), so after a backward step the timer is re-armed for D later. Nothing observes clock changes: setup registers only lifecycle and proximity notifications (:139-160). Bridgeless sends setTimeout through ObjCTimerRegistry into the same class (ObjCTimerRegistry.mm:48-61, wired in RCTInstance.mm:311-316). Android's JavaTimerManager sets targets from nanoTime() (JavaTimerManager.kt:183) and compares them with Choreographer frame time (:294-296), so clock steps do not move them.
https://github.com/react/react-native/issues/11732 reported this on a device with RN 0.35 in 2017, where setting the time back one minute delayed a setInterval by about a minute, with the same diagnosis; it was closed for inactivity and locked. main still has the same code.
We found this in Evolu, a local-first sync library. Its connection watchdog and WebSocket reconnect delays are timers, so after the clock steps back by D, a silently dead connection can show as synced for D.
Steps to reproduce
-
Set Settings > Display & Brightness > Auto-Lock to Never, then run this
App.tsxon an iPhone:import { useEffect, useState } from "react"; import { Text, View } from "react-native"; export default function App() { const [status, setStatus] = useState("waiting for a 60 s setTimeout"); useEffect(() => { const startElapsed = performance.now(); const startWall = Date.now(); const id = setTimeout(() => { const elapsed = Math.round((performance.now() - startElapsed) / 1000); const wall = Math.round((Date.now() - startWall) / 1000); setStatus(`fired after ${elapsed} s; Date.now() moved ${wall} s`); }, 60_000); return () => clearTimeout(id); }, []); return ( <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }} > <Text>{status}</Text> </View> ); } -
Within 60 s, open Settings > General > Date & Time, turn off Set Automatically, and set the time one hour earlier.
-
Return to the app once the 60 s have passed.
We haven't run this on a device. From the code above, the text changes only about an hour later, to fired after 3660 s; Date.now() moved 60 s: the timer waits until the wall clock reaches its original target. A smaller step delays it by that step, as #11732 saw with one minute.
Expected: it fires as soon as you return, about 60 s after the start, as on Android. Time the device spends asleep keeps counting, as it does today.
React Native Version
0.88.1
Affected Platforms
Runtime - iOS
Output of npx @react-native-community/cli info
System:
OS: macOS 26.6.2
CPU: (10) arm64 Apple M5
Memory: 239.14 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 24.22.1
path: /Users/steida/.nvm/versions/node/v24.22.1/bin/node
Yarn: Not Found
npm:
version: 11.19.1
path: /Users/steida/.nvm/versions/node/v24.22.1/bin/npm
Watchman: Not Found
Managers:
CocoaPods:
version: 1.16.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 27.2
- iOS 27.2
- macOS 27.2
- tvOS 27.2
- visionOS 27.2
- watchOS 27.2
Android SDK: Not Found
IDEs:
Android Studio: 2025.3 AI-253.32098.37.2534.15336583
Xcode:
version: 27.2/27B52
path: /usr/bin/xcodebuild
Languages:
Java: Not Found
Ruby:
version: 2.6.10
path: /usr/bin/ruby
(Trimmed after Languages: in our hoisted pnpm workspace the CLI reports the npm packages as Not Found. They are react-native 0.88.1, react 19.3.0 and @react-native-community/cli 20.2.0.)
Stacktrace or Logs
No crash or log. From the code, the app shows: fired after 3660 s; Date.now() moved 60 s.
MANDATORY Reproducer
The App.tsx above is the whole reproducer. It needs a device whose clock can be changed. The source lines in the description show the cause without running it.
Screenshots and Videos
No response
- Ngôn ngữ chính
- C++
- Star
- 127k
- Fork
- 25.5k
- Merge trung bình
- 3 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 235
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của react/react-native
-
Needs: Author Feedback Needs: Repro
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
react/react-native#60059 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Needs: Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
react/react-native#60000 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
`yarn test-ios` exits before building RNTester: `objc-test.sh` launches the WebSocket server script #59433 deletedCó thể đã có người làm @lazerg đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
react/react-native#59939 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primaryCó thể đã có người làm @alleneubank đã nhận 6 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
react/react-native#59919 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
react/react-native#59722 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của react/react-native
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
petercorke/robotics-toolbox-python#943 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:build bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
NatronGitHub/openfx-arena#71 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
upstream-blocked
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ROCm/FastFlowLM#1057 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
NatronGitHub/openfx-gmic#45 ·
Maintainer thường phản hồi trong vòng 1 ngày