fix(ios): prevent crash when a query returns a very large result#1437
Open
datlechin wants to merge 1 commit into
Open
fix(ios): prevent crash when a query returns a very large result#1437datlechin wants to merge 1 commit into
datlechin wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Running a query that returns a very large result could crash the iOS app with an out-of-memory (jetsam) termination. Reported via TestFlight on build 15: comment "Crash", repro "when execute query with large data table".
Root cause
The SQL query editor drained up to 100,000 rows into memory with no back-pressure, no per-app memory budget check, and no memory-pressure handling. The Data Browser had all three; the editor's
handlePressureexisted but was never wired into the view, so it was dead code. The two view models also duplicated the streaming machinery (flush,shrink,apply, batch constants), which is how the editor drifted from the Browser's safety behavior.A memory termination produces a TestFlight "Crash" with no symbolicated stack, which matches the sparse report.
Fix
StreamingResultBuffer: one type that owns row accumulation, batched flushing,shrink, andreset. Both view models delegate to it, so they can't diverge again.os_proc_available_memory()every 500 rows and stops at a 64 MB headroom margin, before jetsam fires, rather than only reacting to memory-pressure signals (which can arrive too late). Backstop cap of 10,000 rows, with the window sized so it never slides, so the first rows are kept.didReceiveMemoryWarningNotificationandMemoryPressureMonitor.currentLevel, matching the Data Browser.An editor result is a forward-only cursor that can't be re-paged, so the editor keeps the first rows and stops, instead of sliding a window and discarding the head like the Data Browser (which can re-fetch pages with LIMIT/OFFSET).
Tests
QueryEditorViewModelTests: cap keeps the head, clean finish, memory-pressure handling, reset.StreamingResultBufferTests: flush / shrink / reset invariants.Notes
xcodebuildand the test bundle (please run the TableProMobile tests). The new localized strings were extracted into the iOS string catalog by an Xcode build, which confirms the iOS target compiled.