Title: fix: Resolve timer bugs causing lost timers and resource leaks by adrian-niculescu · Pull Request #1894 · NativeScript/android · GitHub
Open Graph Title: fix: Resolve timer bugs causing lost timers and resource leaks by adrian-niculescu · Pull Request #1894 · NativeScript/android
X Title: fix: Resolve timer bugs causing lost timers and resource leaks by adrian-niculescu · Pull Request #1894 · NativeScript/android
Description: This PR fixes five bugs in Timers.cpp that could cause timers to be lost, file descriptors to leak, and memory to accumulate.
1. Inverted EAGAIN retry condition (line 162)
When the pipe buffer fills up and write() returns EAGAIN, the retry loop had the wrong condition:
// Before - wrong: continues if timer IS deleted
while (!stopped && deletedTimers_.find(timer->id) != deletedTimers_.end() && ...)
// After - correct: continues if timer is NOT deleted
while (!stopped && deletedTimers_.find(timer->id) == deletedTimers_.end() && ...)
This caused live timers to be silently dropped when the pipe was full, because the loop never executed for timers that weren't deleted.
Additionally, if a timer is cancelled while waiting for buffer space, the fix now cleans up deletedTimers_ to prevent leaking the timer ID:
// After the retry loop
if (deletedTimers_.find(timer->id) != deletedTimers_.end()) {
deletedTimers_.erase(timer->id);
}
2. File descriptor leak (line 192)
Destroy() was closing only the read end of the pipe:
close(fd_[0]);
// fd_[1] never closed - leaked one FD per isolate lifetime
Now both ends are properly closed:
close(fd_[0]);
close(fd_[1]);
3. deletedTimers_ accumulation (line 323)
Immediate timers (delay ≤ 0) skip the sortedTimers_ queue and write directly to the pipe. If cleared before the callback runs, their IDs were added to deletedTimers_ but never removed.
Added cleanup in PumpTimerLoopCallback:
auto it = thiz->timerMap_.find(timerId);
if (it != thiz->timerMap_.end()) {
// ... execute callback ...
} else {
// Timer was cleared before callback ran - clean up
std::lock_guard
Open Graph Description: This PR fixes five bugs in Timers.cpp that could cause timers to be lost, file descriptors to leak, and memory to accumulate. 1. Inverted EAGAIN retry condition (line 162) When the pipe buffer fill...
X Description: This PR fixes five bugs in Timers.cpp that could cause timers to be lost, file descriptors to leak, and memory to accumulate. 1. Inverted EAGAIN retry condition (line 162) When the pipe buffer fill...
Opengraph URL: https://github.com/NativeScript/android/pull/1894
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:5d80cea6-11ef-a46d-e8e7-de505a691a9f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D4DC:204573:874141E:B4FCE29:696E1BC2 |
| html-safe-nonce | fb670002c5f376a9919cff5ce96efe4a158783ad5dfeaff360a3b799e01b56ee |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENERDOjIwNDU3Mzo4NzQxNDFFOkI0RkNFMjk6Njk2RTFCQzIiLCJ2aXNpdG9yX2lkIjoiNDYwMDY0NTg0MTEyMTU4MjAxOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a4eee8be465663bd887186d9c6d9800bfe650c4e8d66c47219f862c8392b21e0 |
| hovercard-subject-tag | pull_request:3065189124 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/1894/files |
| twitter:image | https://avatars.githubusercontent.com/u/15037449?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/15037449?s=400&v=4 |
| og:image:alt | This PR fixes five bugs in Timers.cpp that could cause timers to be lost, file descriptors to leak, and memory to accumulate. 1. Inverted EAGAIN retry condition (line 162) When the pipe buffer fill... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 113cc336e7105fbb9f2ee8beb67c6cc584d65fa66a8a1a5dd236ba66db174af7 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/android git https://github.com/NativeScript/android.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 29137950 |
| octolytics-dimension-repository_nwo | NativeScript/android |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29137950 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/android |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1d23f8b0bc31294c6a73ba2f3adfdd8c7052ca1e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width