Crash task-local: illegal task-local value binding #110
Answered
by
stephencelis
corysullivan
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
stephencelis
Aug 10, 2023
Replies: 1 comment 1 reply
-
@corysullivan That error is due to executing task local code inside an invalid context, like within a func testIllegalTaskLocal() async {
enum Test {
@TaskLocal static var isSetting = false
}
await withTaskGroup(of: Void.self) { group in
Test.$isSetting.withValue(true) {
print(Test.isSetting)
}
print(Test.isSetting)
}
} If you follow your trace to the effect causing the crash, you're likely in a My only guess as to why you didn't encounter this issue earlier is that you were on a version of Dependencies that didn't access the task local at this time. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
corysullivan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@corysullivan That error is due to executing task local code inside an invalid context, like within a
withTaskGroup
block but outside anaddTask
. Here's a vanilla test case demonstrating the issue:If you follow your trace to the effect causing the crash, you're likely in a
withTaskGroup
context. You'll want to avoid accessing dependencies in that scope, and instead move dependency access insidegroup.addTask
, or outside the task group ent…