Skip to content

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

Merged
merged 4 commits into from
Sep 22, 2020

Conversation

rickpasetto
Copy link

@rickpasetto rickpasetto commented Sep 22, 2020

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

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).
public var history: [String]
private let historyQueue = DispatchQueue(label: "MockService_historyQueue")
Copy link

@ps2 ps2 Sep 22, 2020

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.

Copy link
Author

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.

@rickpasetto rickpasetto requested a review from ps2 September 22, 2020 18:36
Copy link

@ps2 ps2 left a 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.

@@ -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]>([])
Copy link

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.

@rickpasetto rickpasetto merged commit d5c4f09 into dev Sep 22, 2020
@rickpasetto rickpasetto deleted the rick/LOOP-1983-prevent-crash-in-MockService branch September 22, 2020 19:02
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.

2 participants