Fix CGo write barrier crashes: move split tunnel + API methods to radiance with RunOffCgoStack#8556
Conversation
There was a problem hiding this comment.
Pull request overview
This PR mitigates macOS CGo write-barrier panics by ensuring LanternCore methods that allocate pointer-bearing Go values don’t run on the CGo callback stack.
Changes:
- Wrap
LanternCore.GetSplitTunnelItemswithcommon.RunOffCgoStackto move slice allocation/JSON marshaling off the CGo callback stack. - Wrap
LanternCore.GetEnabledAppswithcommon.RunOffCgoStackto move map/slice allocations and JSON parsing/marshaling off the CGo callback stack.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Move the complex logic into radiance's SplitTunnel (ItemsJSON and EnabledAppsJSON methods), keeping lantern-core as thin wrappers. Both radiance methods use RunOffCgoStack internally to avoid CGo write barrier panics on macOS. Bumps radiance to pick up the new SplitTunnel methods. Fixes getlantern/engineering#3088 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
326e61e to
4c26b37
Compare
|
@myleshorton FYI Just hit the same crash again but on |
Picks up RunOffCgoStack wrapping for UserData() and FetchUserData() which also deserialize protobuf structs on the CGo callback stack. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Picks up RunOffCgoStack wrapping for Login, Logout, DeleteAccount, and OAuthLoginCallback in addition to UserData and FetchUserData. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
OK thanks added a fix for that too as well as other methods. Good you're catching these, as they theoretically aren't just Mac bugs. |
Resolves go.mod/go.sum conflicts by taking main's versions then updating radiance to the branch with ItemsJSON/EnabledAppsJSON methods that this PR depends on. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Call chain verificationBoth radiance methods are fully wired through to the Dart UI:
The PR replaces ~90 lines of duplicated logic in lantern-core with thin wrappers that delegate to the CGo-safe radiance implementations. |
Summary
GetSplitTunnelItemsandGetEnabledAppslogic into radiance (SplitTunnel.ItemsJSON/SplitTunnel.EnabledAppsJSON), keeping lantern-core as thin wrappers[]byte-returningAPIClientmethods in radiance withRunOffCgoStack:UserData,FetchUserData,Login,Logout,DeleteAccount,OAuthLoginCallbackMotivation
Gomobile-exported functions run on a CGo callback stack whose memory is not covered by the GC heap bitmap. When these methods allocate protobuf structs, maps, or slices and marshal them to
[]byte,bulkBarrierPreWritepanics when copying the return value across the C boundary.The crash log from #3088 shows:
Changes
lantern-core/core.go:
GetSplitTunnelItems→ thin wrapper callingst.ItemsJSON(filterType)GetEnabledApps→ thin wrapper callingst.EnabledAppsJSON()radiance (companion PR getlantern/radiance#363):
SplitTunnel.ItemsJSON/EnabledAppsJSON— new methods withRunOffCgoStackAPIClient.UserData,FetchUserData,Login,Logout,DeleteAccount,OAuthLoginCallback— all wrapped withRunOffCgoStackTest plan
Fixes getlantern/engineering#3088
🤖 Generated with Claude Code