Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cache中在io线程中encode引发的死锁 #219

@myongong

Description

@myongong

Thread 3:
0 libsystem_kernel.dylib 0x00000001e2cafaf8 __ulock_wait2 + 8
1 libsystem_platform.dylib 0x000000021c0f8630 os_unfair_lock_lock_slow + 176 (lock.c:608)
2 libobjc.A.dylib 0x000000018f020f3c objc_readClassPair + 84 (objc-runtime-new.mm:9085)
3 libswiftCore.dylib 0x00000001904f1c64 swift_initClassMetadataImpl(swift::TargetClassMetadata<swift::InProcess, swift::TargetAnyClassMetadataObjCInteropswift::InProcess>, swift::ClassLayoutFlags, unsigned long, swift::TargetTypeLayo... + 4412 (Metadata.cpp:4312)
4 libswiftCore.dylib 0x0000000190493af0 type metadata completion function for _KeyedEncodingContainerBox + 112 (:0)
5 libswiftCore.dylib 0x00000001904fe7a4 swift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const
>::doInitialization(swift::MetadataWaitQueue::Worker&, swift::MetadataRequest) + 860 (MetadataCache.h:1300)
6 libswiftCore.dylib 0x00000001904eb668 swift_getGenericMetadata(swift::MetadataRequest, void const* const*, swift::TargetTypeContextDescriptorswift::InProcess const*) + 2336 (Metadata.cpp:982)
7 libswiftCore.dylib 0x00000001904b6564 __swift_instantiateGenericMetadata + 36 (:0)
8 libswiftCore.dylib 0x000000019018d2a0 KeyedEncodingContainer.init(
:) + 48 (Codable.swift:547)
9 Foundation 0x000000019082cf08 __PlistEncoderBPlist.container(keyedBy:) + 344 (BPlistEncodingFormat.swift:94)
10 Foundation 0x000000019082cf4c protocol witness for Encoder.container(keyedBy:) in conformance __PlistEncoderBPlist + 24 (:0)
11 Tiercel 0x0000000106ff22c0 DownloadTask.encode(to:) + 176 (DownloadTask.swift:120)
12 Tiercel 0x000000010701e8c8 protocol witness for Encodable.encode(to:) in conformance Task + 44 (/:0)
13 libswiftCore.dylib 0x0000000190490b8c dispatch thunk of Encodable.encode(to:) + 32
14 Foundation 0x0000000190832af0 specialized closure #1 in __PlistEncoderBPlist.wrapGeneric<A, B>(
:for:
:) + 144 (BPlistEncodingFormat.swift:500)
15 Foundation 0x0000000190832b30 partial apply for specialized closure #1 in __PlistEncoderBPlist.wrapGeneric<A, B>(:for::) + 24 (:0)
16 Foundation 0x000000019082c84c specialized __PlistEncoderBPlist.wrapGeneric(:for::) + 368 (BPlistEncodingFormat.swift:515)
17 Foundation 0x0000000190832a2c specialized __PlistEncoderBPlist.wrapGeneric<A, B>(
:for::) + 836 (BPlistEncodingFormat.swift:499)
18 Foundation 0x000000019086ecc4 PlistUnkeyedEncodingContainerBPlist.encode
(:) + 292 (BPlistEncodingFormat.swift:354)
19 Foundation 0x000000019086eb98 protocol witness for UnkeyedEncodingContainer.encode(
:) in conformance PlistUnkeyedEncodingContainerBPlist + 16 (:0)
20 libswiftCore.dylib 0x00000001901b0e60 Array
.encode(to:) + 440 (Codable.swift:6032)
21 libswiftCore.dylib 0x00000001901b0fa0 protocol witness for Encodable.encode(to:) in conformance [A] + 32 (:0)
22 libswiftCore.dylib 0x0000000190490b8c dispatch thunk of Encodable.encode(to:) + 32
23 Foundation 0x0000000190832af0 specialized closure #1 in __PlistEncoderBPlist.wrapGeneric<A, B>(
:for::) + 144 (BPlistEncodingFormat.swift:500)
24 Foundation 0x0000000190832b30 partial apply for specialized closure #1 in __PlistEncoderBPlist.wrapGeneric<A, B>(
:for::) + 24 (:0)
25 Foundation 0x000000019082c84c specialized __PlistEncoderBPlist.wrapGeneric
(:for::) + 368 (BPlistEncodingFormat.swift:515)
26 Foundation 0x0000000190832a2c specialized __PlistEncoderBPlist.wrapGeneric<A, B>(:for::) + 836 (BPlistEncodingFormat.swift:499)
27 Foundation 0x0000000190832558 PropertyListEncoder.encodeToTopLevelContainerBPlist(:) + 188 (PlistEncoder.swift:216)
28 Foundation 0x0000000190831f54 PropertyListEncoder.encodeBPlist
(:) + 44 (PlistEncoder.swift:120)
29 Foundation 0x00000001908318c4 PropertyListEncoder.encode(
:) + 140 (PlistEncoder.swift:103)
30 Foundation 0x0000000190831684 dispatch thunk of PropertyListEncoder.encode(:) + 48
31 Tiercel 0x0000000106feb830 closure #1 in Cache.storeTasks(
:) + 360 (Cache.swift:259)
32 Tiercel 0x0000000106fea818 thunk for @escaping @callee_guaranteed () -> () + 28 (/:0)
33 Tiercel 0x0000000107000d18 closure #1 in closure #1 in Debouncer.execute(label:time:execute:) + 44 (Protected.swift:127)
34 Tiercel 0x0000000106fea818 thunk for @escaping @callee_guaranteed () -> () + 28 (/:0)
35 libdispatch.dylib 0x0000000199a2c2b8 _dispatch_block_async_invoke2 + 148 (queue.c:574)
36 libdispatch.dylib 0x0000000199a36584 _dispatch_client_callout + 16 (client_callout.mm:85)
37 libdispatch.dylib 0x0000000199a21560 _dispatch_continuation_pop + 596 (queue.c:325)
38 libdispatch.dylib 0x0000000199a34348 _dispatch_source_latch_and_call + 396 (source.c:601)
39 libdispatch.dylib 0x0000000199a33020 _dispatch_source_invoke + 844 (source.c:966)
40 libdispatch.dylib 0x0000000199a25138 _dispatch_lane_serial_drain + 332 (queue.c:3939)
41 libdispatch.dylib 0x0000000199a25de0 _dispatch_lane_invoke + 440 (queue.c:4030)
42 libdispatch.dylib 0x0000000199a301dc _dispatch_root_queue_drain_deferred_wlh + 292 (queue.c:7198)
43 libdispatch.dylib 0x0000000199a2fa60 _dispatch_workloop_worker_thread + 540 (queue.c:6792)
44 libsystem_pthread.dylib 0x000000021c1a0a0c _pthread_wqthread + 292 (pthread.c:2696)
45 libsystem_pthread.dylib 0x000000021c1a0aac start_wqthread + 8

在 Cache 的 storeTasks 方法中,在 io 线程中对 tasks 进行存储时,需要 encode tasks,由于 encode 获取 encode 对象元数据不是线程安全的,有几率产生死锁,不能在全局线程中 encode 对象。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions