René's URL Explorer Experiment


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 lock(thiz->mutex); thiz->deletedTimers_.erase(timerId); } 4. Data race on stopped flag (Timers.h line 131) The stopped flag was written under mutex in Destroy() but read without synchronization in PumpTimerLoopCallback(), causing undefined behavior per C++ standard. // Before bool stopped = false; // After std::atomic stopped = false; 5. Non-EAGAIN write errors drop timers (line 92) The condition if (result != -1 || errno != EAGAIN) treated all non-EAGAIN errors (EPIPE, EBADF, EINTR) as success, disabling fallback scheduling: // Before - wrong: treats EPIPE/EBADF as success if (result != -1 || errno != EAGAIN) { needsScheduling = false; // timer lost! } // After - correct: only success disables scheduling if (result != -1) { needsScheduling = false; } else if (errno == EAGAIN) { isBufferFull = true; } // Other errors: needsScheduling stays true, timer goes to sortedTimers_ Additional fix: isBufferFull reset guard (line 171) The isBufferFull optimization flag was being reset even when write() failed with non-EAGAIN errors: // Before - resets on any non-EAGAIN result } else if (isBufferFull.load() && ...) { isBufferFull = false; } // After - only resets on actual success } else if (result != -1 && isBufferFull.load() && ...) { isBufferFull = false; } This prevents incorrectly re-enabling the immediate timer optimization when the pipe is broken.

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

direct link

Domain: patch-diff.githubusercontent.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:5d80cea6-11ef-a46d-e8e7-de505a691a9f
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD4DC:204573:874141E:B4FCE29:696E1BC2
html-safe-noncefb670002c5f376a9919cff5ce96efe4a158783ad5dfeaff360a3b799e01b56ee
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENERDOjIwNDU3Mzo4NzQxNDFFOkI0RkNFMjk6Njk2RTFCQzIiLCJ2aXNpdG9yX2lkIjoiNDYwMDY0NTg0MTEyMTU4MjAxOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaca4eee8be465663bd887186d9c6d9800bfe650c4e8d66c47219f862c8392b21e0
hovercard-subject-tagpull_request:3065189124
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/1894/files
twitter:imagehttps://avatars.githubusercontent.com/u/15037449?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/15037449?s=400&v=4
og:image:altThis 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_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None113cc336e7105fbb9f2ee8beb67c6cc584d65fa66a8a1a5dd236ba66db174af7
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/NativeScript/android git https://github.com/NativeScript/android.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id29137950
octolytics-dimension-repository_nwoNativeScript/android
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id29137950
octolytics-dimension-repository_network_root_nwoNativeScript/android
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release1d23f8b0bc31294c6a73ba2f3adfdd8c7052ca1e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F1894%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F1894%2Ffiles
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=NativeScript%2Fandroid
Reloadhttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
Reloadhttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
Reloadhttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
NativeScript https://patch-diff.githubusercontent.com/NativeScript
androidhttps://patch-diff.githubusercontent.com/NativeScript/android
Please reload this pagehttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2FNativeScript%2Fandroid
Fork 142 https://patch-diff.githubusercontent.com/login?return_to=%2FNativeScript%2Fandroid
Star 558 https://patch-diff.githubusercontent.com/login?return_to=%2FNativeScript%2Fandroid
Code https://patch-diff.githubusercontent.com/NativeScript/android
Issues 96 https://patch-diff.githubusercontent.com/NativeScript/android/issues
Pull requests 14 https://patch-diff.githubusercontent.com/NativeScript/android/pulls
Actions https://patch-diff.githubusercontent.com/NativeScript/android/actions
Projects 0 https://patch-diff.githubusercontent.com/NativeScript/android/projects
Wiki https://patch-diff.githubusercontent.com/NativeScript/android/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/NativeScript/android/security
Please reload this pagehttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
Insights https://patch-diff.githubusercontent.com/NativeScript/android/pulse
Code https://patch-diff.githubusercontent.com/NativeScript/android
Issues https://patch-diff.githubusercontent.com/NativeScript/android/issues
Pull requests https://patch-diff.githubusercontent.com/NativeScript/android/pulls
Actions https://patch-diff.githubusercontent.com/NativeScript/android/actions
Projects https://patch-diff.githubusercontent.com/NativeScript/android/projects
Wiki https://patch-diff.githubusercontent.com/NativeScript/android/wiki
Security https://patch-diff.githubusercontent.com/NativeScript/android/security
Insights https://patch-diff.githubusercontent.com/NativeScript/android/pulse
Sign up for GitHub https://patch-diff.githubusercontent.com/signup?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://patch-diff.githubusercontent.com/login?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
adrian-niculescuhttps://patch-diff.githubusercontent.com/adrian-niculescu
NativeScript:mainhttps://patch-diff.githubusercontent.com/NativeScript/android/tree/main
adrian-niculescu:fix-timer-bugshttps://patch-diff.githubusercontent.com/adrian-niculescu/NativeScript-Android/tree/fix-timer-bugs
Conversation 2 https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894
Commits 1 https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/commits
Checks 0 https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/checks
Files changed https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
Please reload this pagehttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
fix: Resolve timer bugs causing lost timers and resource leaks https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#top
Show all changes 1 commit https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
9ba263c fix: resolve timer bugs causing lost timers and resource leaks adrian-niculescu Dec 2, 2025 https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/commits/9ba263ce30e7b6311f138a871edcded0de4935b3
Clear filters https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
Please reload this pagehttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
Please reload this pagehttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files
Timers.cpp https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-efa747f37049594f7502d55b495d8985859dae41cb2b705518a85f5896ddcb8b
Timers.h https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-83595e8aa4a82e7ed27be66adfc4c3fe443f048154662272aa98236219b5faa4
test-app/runtime/src/main/cpp/Timers.cpphttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-efa747f37049594f7502d55b495d8985859dae41cb2b705518a85f5896ddcb8b
View file https://patch-diff.githubusercontent.com/NativeScript/android/blob/9ba263ce30e7b6311f138a871edcded0de4935b3/test-app/runtime/src/main/cpp/Timers.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/{{ revealButtonHref }}
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-efa747f37049594f7502d55b495d8985859dae41cb2b705518a85f5896ddcb8b
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-efa747f37049594f7502d55b495d8985859dae41cb2b705518a85f5896ddcb8b
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-efa747f37049594f7502d55b495d8985859dae41cb2b705518a85f5896ddcb8b
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-efa747f37049594f7502d55b495d8985859dae41cb2b705518a85f5896ddcb8b
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-efa747f37049594f7502d55b495d8985859dae41cb2b705518a85f5896ddcb8b
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-efa747f37049594f7502d55b495d8985859dae41cb2b705518a85f5896ddcb8b
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-efa747f37049594f7502d55b495d8985859dae41cb2b705518a85f5896ddcb8b
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-efa747f37049594f7502d55b495d8985859dae41cb2b705518a85f5896ddcb8b
test-app/runtime/src/main/cpp/Timers.hhttps://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-83595e8aa4a82e7ed27be66adfc4c3fe443f048154662272aa98236219b5faa4
View file https://patch-diff.githubusercontent.com/NativeScript/android/blob/9ba263ce30e7b6311f138a871edcded0de4935b3/test-app/runtime/src/main/cpp/Timers.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/{{ revealButtonHref }}
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-83595e8aa4a82e7ed27be66adfc4c3fe443f048154662272aa98236219b5faa4
https://patch-diff.githubusercontent.com/NativeScript/android/pull/1894/files#diff-83595e8aa4a82e7ed27be66adfc4c3fe443f048154662272aa98236219b5faa4
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.