Skip to content

Add thread safety for background task execution and context-only bridge registration#83

Merged
shanerbaner82 merged 2 commits intomainfrom
feature/background-task-thread-safety
Apr 3, 2026
Merged

Add thread safety for background task execution and context-only bridge registration#83
shanerbaner82 merged 2 commits intomainfrom
feature/background-task-thread-safety

Conversation

@shanerbaner82
Copy link
Copy Markdown
Contributor

Summary

  • Add pthread mutex around runArtisanCommand in php_bridge.c to prevent race condition with ephemeral runtime — prevents SIGABRT/zend_mm_panic crashes when WorkManager fires tasks during app initialization
  • Add @Synchronized to copyAssetFile in LaravelEnvironment.kt to prevent SIGSEGV when multiple threads write cacert.pem simultaneously in DEBUG mode
  • Generate registerContextOnlyBridgeFunctions(context) in the plugin build system so WorkManager workers can register bridge functions on cold boot without an Activity
  • Remove verbose Edge.Set component logging

Test plan

  • Build and deploy to Android device/emulator
  • Boot app with background-tasks plugin — no crashes during init
  • Close app, wait 15 minutes — WorkManager fires tasks via cold boot
  • Verify bridge functions registered on cold boot (LocalNotification.Show works)
  • Force-close and reopen — no crash from stale WorkManager retries
  • Verify existing plugin functionality unaffected (camera, biometrics, etc.)

…ge registration

- Add pthread mutex around runArtisanCommand to prevent race with ephemeral runtime
- Add @synchronized to copyAssetFile to prevent concurrent file write crashes
- Generate registerContextOnlyBridgeFunctions() for WorkManager cold-boot scenarios
- Split bridge function registration into activity-based and context-only variants
- Remove verbose Edge.Set component logging
Concurrent POSTs to different endpoints (e.g. /_native/api/events and
/livewire/update) shared a single lastPostData slot. When both fired
near-simultaneously, shouldInterceptRequest on one thread would consume
the other's body, causing Livewire to receive an empty payload and 404.

Replace the single-slot lastPostData with per-URL-path queues so each
endpoint's POST data is isolated and consumed by the correct request.
@shanerbaner82 shanerbaner82 merged commit 39bd705 into main Apr 3, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant