-
Notifications
You must be signed in to change notification settings - Fork 4
LOOP-1983: Prevent crash in MockService #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Stack traces seem to indicate a crash in MockService. Either this array is being illegally accessed from multiple threads (more likely), or it is running out of memory (less likely, but still plausible given that says he’s set the CGM update every 5 sec and it has run for hours).
MockKit/MockService.swift
Outdated
public var history: [String] | ||
private let historyQueue = DispatchQueue(label: "MockService_historyQueue") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like history is currently being accessed from UI code in MockServiceSettingsViewController.
Putting history writing onto a new thread wouldn't solve the issue, as you'd still have writing from one thread (historyQueue) and reading on another thread (main).
I'd recommend just dispatching the writes onto .main instead. Then both reads and writes will be on .main. No need to create new queue.
If you did want to just protect this one var, and keep writing on background threads, locking would be preferable to creating a new queue, locking being the more lightweight option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I see now that history
is public
. I'll fix this to use locking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just a naming comment.
MockKit/MockService.swift
Outdated
@@ -25,25 +25,24 @@ public final class MockService: Service { | |||
|
|||
public let maxHistoryItems = 1000 | |||
|
|||
public var history: [String] | |||
private let historyQueue = DispatchQueue(label: "MockService_historyQueue") | |||
private var _history = Locked<[String]>([]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] the pattern we've been using is to name this variable lockedHistory
, rather than have an underscore.
Stack traces seem to indicate a crash in MockService. Either this array is being illegally accessed from multiple threads (more likely), or it is running out of memory (less likely, but still plausible given that says he’s set the CGM update every 5 sec and it has run for hours).
LOOP-1983