René's URL Explorer Experiment


Title: Make LiveSync writes atomic instead of locking the runtime's reads by edusperoni · Pull Request #2022 · NativeScript/android · GitHub

Open Graph Title: Make LiveSync writes atomic instead of locking the runtime's reads by edusperoni · Pull Request #2022 · NativeScript/android

X Title: Make LiveSync writes atomic instead of locking the runtime's reads by edusperoni · Pull Request #2022 · NativeScript/android

Description: Description m_fileWriteMutex paired LiveSync's file writes against Runtime::ReadFileText, so the runtime would not compile a half-written hot-synced module. It could not deliver that, for three independent reasons: Wrong scope. It is a non-static member (Runtime.h), so LiveSync locking one runtime excludes nothing on a worker's thread — precisely the case that matters now that workers run on their own detached threads. Taken after the damage. The lock landed after prepareFile() deleted the file and the FileOutputStream constructor truncated it, so it covered only fos.write and not the window a reader actually hits. Unmatched unlock. The finally called runtime.unlock() even when lock() had never been reached (a throw from mkdirs() or the FileOutputStream constructor). Unlocking a std::mutex this thread does not own is UB, and on bionic can release a lock the JS thread holds inside ReadFileText. Rather than fix the locking, this inverts the approach: make the write atomic instead of locking the readers. Writes now go to a sibling temp file which is renamed over the target. rename(2) within a directory is atomic, so a reader gets either the whole previous file or the whole new one — on every runtime and every thread, with no shared state to scope wrongly. That also closes the delete/truncate window that no reader-side lock could have covered, and takes a mutex off every debug module read. java.nio.file's ATOMIC_MOVE is unavailable at minSdk 21 (it needs 26), so this uses File.createTempFile(prefix, suffix, parentDir) plus File.renameTo, which maps to rename(2) on every API level. The temp file must be a sibling — rename is only atomic within one filesystem. m_fileWriteMutex, Runtime::Lock/Unlock, both lock_guards, the two JNI entry points and the private native lock/unlock(int) declarations are removed. com.tns.Runtime.lock()/unlock() remain as @Deprecated no-ops, since they are public API and external tooling may call them. Current behaviour: LiveSync truncates the target in place and takes a per-runtime mutex around part of the write; readers on other runtimes are unprotected, and an early throw unlocks a mutex the thread does not hold. New behaviour: LiveSync writes atomically; readers never observe a partial file, and there is no lock on the read path. Found while removing File::Buffer in 7c9c3db — this mutex superficially looked like it guarded that shared buffer. It never did. Does your commit message include the wording below to reference a specific issue in this repo? Fixes the m_fileWriteMutex item in #2020. Related Pull Requests Follows 7c9c3db on main (process-global state shared across isolates), which surfaced this. Does your pull request have unit tests? No. The test suite does not exercise LiveSync at all — it is a debug socket service driven by the CLI over a LocalServerSocket, with no harness in the runtime test app. So the green run below proves the code builds and nothing else regressed, not that hot-sync still works. Verified: :runtime:externalNativeBuildDebug -Pabis=arm64-v8a — compiles and links clean ./gradlew runtestsAndVerifyResults — 1038/1038 passed, 0 failed Manual check still needed before merge: ns run android on a device/emulator Edit a .js/.ts file in the app while it runs Confirm the file hot-syncs and the app reloads (i.e. createOrOverrideFile → renameTo succeeds and DO_SYNC_OPERATION still triggers livesync.js) Worth also confirming a new file (not just an overwrite) and a deleted file, since prepareFile() is gone Summary by CodeRabbit Bug Fixes Improved runtime file updates by writing changes safely and replacing files atomically. Automatically creates missing parent directories during file updates. Cleans up temporary files when an update fails. Removed obsolete file-locking behavior that could interfere with runtime file access.

Open Graph Description: Description m_fileWriteMutex paired LiveSync's file writes against Runtime::ReadFileText, so the runtime would not compile a half-written hot-synced module. It could not deliver that, for three...

X Description: Description m_fileWriteMutex paired LiveSync's file writes against Runtime::ReadFileText, so the runtime would not compile a half-written hot-synced module. It could not deliver that, for t...

Opengraph URL: https://github.com/NativeScript/android/pull/2022

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:28bd1ccb-8716-7540-945b-eca41e3fdc6c
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDFC8:1D86C4:15B7E31:1B9D2B7:6B0131E4
html-safe-noncee89b5eed727fc21b76ce9fcf7cbd4296634b24e143c875bef7d81b51b5067de6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkM4OjFEODZDNDoxNUI3RTMxOjFCOUQyQjc6NkIwMTMxRTQiLCJ2aXNpdG9yX2lkIjoiNjQ3NzU3MTEzMzg5MjgwMDk5NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace55b727914cd5154a06ac6681f81a9ce081780e91463d197045ee72efa6a38ac
hovercard-subject-tagpull_request:4325724171
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/2022/files
twitter:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
og:image:altDescription m_fileWriteMutex paired LiveSync's file writes against Runtime::ReadFileText, so the runtime would not compile a half-written hot-synced module. It could not deliver that, for three...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/NativeScript/android/pull/2022/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2022%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2022%2Ffiles
Sign uphttps://github.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://github.com/NativeScript/android/pull/2022/files
Reloadhttps://github.com/NativeScript/android/pull/2022/files
Reloadhttps://github.com/NativeScript/android/pull/2022/files
NativeScripthttps://github.com/NativeScript
androidhttps://github.com/NativeScript/android
Codehttps://github.com/NativeScript/android
Issues106 (106)https://github.com/NativeScript/android/issues
Pull requests24 (24)https://github.com/NativeScript/android/pulls
Actionshttps://github.com/NativeScript/android/actions
Projectshttps://github.com/NativeScript/android/projects
Wikihttps://github.com/NativeScript/android/wiki
Security and qualityhttps://github.com/NativeScript/android/security
Insightshttps://github.com/NativeScript/android/insights
Sign up for GitHub https://github.com/signup?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
edusperonihttps://github.com/edusperoni
mainhttps://github.com/NativeScript/android/tree/main
fix/livesync-atomic-writehttps://github.com/NativeScript/android/tree/fix/livesync-atomic-write
Conversation 4 https://github.com/NativeScript/android/pull/2022
Commits 1 https://github.com/NativeScript/android/pull/2022/commits
Checks 7 https://github.com/NativeScript/android/pull/2022/checks
Files changed 5 https://github.com/NativeScript/android/pull/2022/files
Make LiveSync writes atomic instead of locking the runtime's reads https://github.com/NativeScript/android/pull/2022/files#top
Show all changes 1 commit https://github.com/NativeScript/android/pull/2022/files
17f529e fix: make LiveSync writes atomic instead of locking the runtime's reads edusperoni Aug 20, 2026 https://github.com/NativeScript/android/pull/2022/commits/17f529ee8f7e93605e89fc9d9ba89abc74f96105
Clear filters https://github.com/NativeScript/android/pull/2022/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2022/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2022/files
NativeScriptSyncServiceSocketImpl.java https://github.com/NativeScript/android/pull/2022/files#diff-c1f14d853e7bc57ed5012270bafa7fb69e3da37634491e02c3c26553bfe9965b
Runtime.cpp https://github.com/NativeScript/android/pull/2022/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
Runtime.h https://github.com/NativeScript/android/pull/2022/files#diff-87f802d33bb6047fdb5ef6dc8d73551485ecb092edff4de77ecc9affc3e9341c
com_tns_Runtime.cpp https://github.com/NativeScript/android/pull/2022/files#diff-12525df874d33d128becf0dc90001af73fcb89c72d20a9f185d5070848daef23
Runtime.java https://github.com/NativeScript/android/pull/2022/files#diff-cf9bb4e9ca1a476cacd6e270fc8bcd12c71f89d52d272915bc99df57b3581f59
test-app/app/src/debug/java/com/tns/NativeScriptSyncServiceSocketImpl.javahttps://github.com/NativeScript/android/pull/2022/files#diff-c1f14d853e7bc57ed5012270bafa7fb69e3da37634491e02c3c26553bfe9965b
View file https://github.com/NativeScript/android/blob/17f529ee8f7e93605e89fc9d9ba89abc74f96105/test-app/app/src/debug/java/com/tns/NativeScriptSyncServiceSocketImpl.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2022/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2022/files#diff-c1f14d853e7bc57ed5012270bafa7fb69e3da37634491e02c3c26553bfe9965b
coderabbitaihttps://github.com/apps/coderabbitai
Aug 20, 2026https://github.com/NativeScript/android/pull/2022/files#r3824510183
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/NativeScript/android/pull/2022/files
coderabbitaihttps://github.com/apps/coderabbitai
Aug 20, 2026https://github.com/NativeScript/android/pull/2022/files#r3824510208
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/NativeScript/android/pull/2022/files
https://github.com/NativeScript/android/pull/2022/files#diff-c1f14d853e7bc57ed5012270bafa7fb69e3da37634491e02c3c26553bfe9965b
https://github.com/NativeScript/android/pull/2022/files#diff-c1f14d853e7bc57ed5012270bafa7fb69e3da37634491e02c3c26553bfe9965b
test-app/runtime/src/main/cpp/Runtime.cpphttps://github.com/NativeScript/android/pull/2022/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
View file https://github.com/NativeScript/android/blob/17f529ee8f7e93605e89fc9d9ba89abc74f96105/test-app/runtime/src/main/cpp/Runtime.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2022/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2022/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
https://github.com/NativeScript/android/pull/2022/files#diff-b9490640f5d26f7cd6b9a176a2142b8e985a6aac9e2d64287de37fc694e80cc3
test-app/runtime/src/main/cpp/Runtime.hhttps://github.com/NativeScript/android/pull/2022/files#diff-87f802d33bb6047fdb5ef6dc8d73551485ecb092edff4de77ecc9affc3e9341c
View file https://github.com/NativeScript/android/blob/17f529ee8f7e93605e89fc9d9ba89abc74f96105/test-app/runtime/src/main/cpp/Runtime.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2022/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2022/files#diff-87f802d33bb6047fdb5ef6dc8d73551485ecb092edff4de77ecc9affc3e9341c
https://github.com/NativeScript/android/pull/2022/files#diff-87f802d33bb6047fdb5ef6dc8d73551485ecb092edff4de77ecc9affc3e9341c
https://github.com/NativeScript/android/pull/2022/files#diff-87f802d33bb6047fdb5ef6dc8d73551485ecb092edff4de77ecc9affc3e9341c
https://github.com/NativeScript/android/pull/2022/files#diff-87f802d33bb6047fdb5ef6dc8d73551485ecb092edff4de77ecc9affc3e9341c
test-app/runtime/src/main/cpp/com_tns_Runtime.cpphttps://github.com/NativeScript/android/pull/2022/files#diff-12525df874d33d128becf0dc90001af73fcb89c72d20a9f185d5070848daef23
View file https://github.com/NativeScript/android/blob/17f529ee8f7e93605e89fc9d9ba89abc74f96105/test-app/runtime/src/main/cpp/com_tns_Runtime.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2022/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2022/files#diff-12525df874d33d128becf0dc90001af73fcb89c72d20a9f185d5070848daef23
https://github.com/NativeScript/android/pull/2022/files#diff-12525df874d33d128becf0dc90001af73fcb89c72d20a9f185d5070848daef23
test-app/runtime/src/main/java/com/tns/Runtime.javahttps://github.com/NativeScript/android/pull/2022/files#diff-cf9bb4e9ca1a476cacd6e270fc8bcd12c71f89d52d272915bc99df57b3581f59
View file https://github.com/NativeScript/android/blob/17f529ee8f7e93605e89fc9d9ba89abc74f96105/test-app/runtime/src/main/java/com/tns/Runtime.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2022/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2022/files#diff-cf9bb4e9ca1a476cacd6e270fc8bcd12c71f89d52d272915bc99df57b3581f59
https://github.com/NativeScript/android/pull/2022/files#diff-cf9bb4e9ca1a476cacd6e270fc8bcd12c71f89d52d272915bc99df57b3581f59
https://github.com/NativeScript/android/pull/2022/files#diff-cf9bb4e9ca1a476cacd6e270fc8bcd12c71f89d52d272915bc99df57b3581f59
https://github.com/NativeScript/android/pull/2022/files#diff-cf9bb4e9ca1a476cacd6e270fc8bcd12c71f89d52d272915bc99df57b3581f59
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.