-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Solved threading problem by null checking removed queued inputs
[Issue reported by Duolingo](https://2dimensions.slack.com/archives/C029X99PETE/p1731696582702019). Looks like a threading issue around access to the concurrent queue. The root of their trace is the artboard `advance`, called from our native worker thread. `processAllInputs` is iterating through a `ConcurrentLinkedQueue` holding the inputs. We check: ```kotlin while (changedInputs.isNotEmpty()) { val input = changedInputs.remove() ``` There could be a small window where `isNotEmpty` returns true and `remove` has nothing to remove. I'm not sure exactly what would cause that - something on a different thread, likely the main thread, would have to empty the queue, maybe a call to `reset` somewhere. The [docs for remove](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/AbstractQueue.html#remove()) show the exception theyre're getting. We assume because we just checked that it's not empty, `remove` should return an element, but it seems this assumption is not safe given the scenario above. We can likely protect against this by using the more forgiving [poll](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Queue.html#poll()) method which returns `null` instead of throwing. Then we can null check before proceeding. Alternatively, we can use the `ReentrantLock`. Removing from this queue in `processAllInputs` is protected while clearing from `reset` it is not. We could wrap reset in a synchronous block on the same lock. Let me know if this approach is preferred. Diffs= 7757e65a9b fix: Solved threading problem by null checking removed queued inputs (#8594) Co-authored-by: Erik <[email protected]>
- Loading branch information
1 parent
ad8b5e4
commit 1081f88
Showing
3 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
08df0095bbf9616cebaec7eb930c4b146bbcb2cf | ||
7757e65a9bef68432a983ef74297be14800b302a |
This file contains 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
This file contains 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