Skip to content
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

🐞 Bug Report: 升级到2.10.0 之后经常Crash #721

Closed
5 of 6 tasks
MobsMao opened this issue Nov 8, 2024 · 16 comments
Closed
5 of 6 tasks

🐞 Bug Report: 升级到2.10.0 之后经常Crash #721

MobsMao opened this issue Nov 8, 2024 · 16 comments
Assignees
Labels
bug Something isn't working fixed in next release The issue will be closed once next release is available

Comments

@MobsMao
Copy link

MobsMao commented Nov 8, 2024

Please confirm the following:

  • Be sure to check out FAQ
  • I have carefully read the README
  • I have searched through the issues page but couldn't find a solution.(Including issue that has been closed)
  • Easydict has been upgraded to the latest version
  • I understand and agree to the above, and understand that the project maintainer has limited energy, issues that do not follow the rules may be ignored or closed directly

Problem description

经常会在需要使用的时候发现EasyDict程序已经没有在运行了, 这个问题是在升级到最新2.10.0之后出现的.

Is the issue consistently reproducible?

Reproducible

Steps to Reproduce

没有特定的触发路径以及提示.
每次在使用后不管, 下次使用时 (一般是option+A呼出小窗口) 会发现无法呼出, ,并且程序已经退出.

Screenshot

Runtime log(zip file)

Easydict log 2024-11-08 14-48-52-019.zip

Expected result

稳定运行

Proposed solution (optional)

No response

Device type and OS version

2019 16 inch mbp, 6-Core i7 Processor, MacOS 15.1

Are you willing to submit a PR to fix this issue?

  • I'm willing to submit a PR to fix this issue
@MobsMao MobsMao added the bug Something isn't working label Nov 8, 2024
Copy link

github-actions bot commented Nov 8, 2024

Hello MobsMao, Thank you for your first issue contribution 🎉

@Word2VecT
Copy link

有同样的问题,mbp m3

@nathanwhy
Copy link

Signal Exception:
Signal SIGSEGV was raised.
Call Stack:
1 libsystem_platform.dylib 0x0000000194313584 _sigtramp + 56
2 CoreFoundation 0x00000001943a2f64 -[__NSFastEnumerationEnumerator initWithObject:] + 128
3 Foundation 0x0000000195502348 -[NSConcreteMapTable keyEnumerator] + 40
4 AppKit 0x000000019844fc34 -[_NSPasteboardOwnersCollection handleOwnershipChange] + 36
5 AppKit 0x0000000198352d24 _NSPasteboardDeclareTypes + 80
6 Easydict 0x0000000104cc0ce0 Easydict + 3017952
7 Easydict 0x0000000104cc09a5 Easydict + 3017125
8 Easydict 0x0000000104b1fc21 Easydict + 1309729
9 Easydict 0x0000000104aa3ed1 Easydict + 802513
10 Easydict 0x0000000104aa3ed1 Easydict + 802513
11 Easydict 0x0000000104aa3ed1 Easydict + 802513
12 Easydict 0x0000000104aa3ed1 Easydict + 802513
13 Easydict 0x0000000104aa3ed1 Easydict + 802513
14 Easydict 0x0000000104ad6649 Easydict + 1009225
15 Easydict 0x0000000104aa3d0d Easydict + 802061
16 libswift_Concurrency.dylib 0x000000025c4570f9 _ZL23completeTaskWithClosurePN5swift12AsyncContextEPNS_10SwiftErrorE + 1
threadInfo:
<NSThread: 0x600001438640>{number = 42, name = (null)}

@tisfeng
Copy link
Owner

tisfeng commented Nov 8, 2024

ok,我看一下。

@tisfeng
Copy link
Owner

tisfeng commented Nov 8, 2024

简单看了一下日志,似乎都是剪贴板 NSPasteboard 崩溃,很奇怪的问题,也不好复现,我想想怎么解决。

@tisfeng tisfeng self-assigned this Nov 8, 2024
@JieBaiYou
Copy link

有同样的问题 mbp m1

@GuanCun
Copy link

GuanCun commented Nov 9, 2024

Easydict 非常好用,但是我近期也有此困惑,而且我有时候搜索是太急了,连续敲多了几下回车键,它立马就闪退出去了。

Easydict 2.10.0
mbp m1pro
MacOS 15.0.1

@tisfeng
Copy link
Owner

tisfeng commented Nov 9, 2024

找到一个类似的日志记录,显示 SelectedTextKit 内部崩溃,应该是多线程访问 NSPasteboard 出现了异常。

(extension in SelectedTextKit):__C.NSPasteboard.saveCurrentContents() -> ()
NSPasteboard+Extension.swift, line 36
Incident Identifier: 9d64806f-0ae6-4226-98e0-9354ff213f94
CrashReporter Key:   00F202A0-5BF2-48DF-8535-E31D38AE7391
Hardware Model:      MacBookPro17,1
Process:         Easydict [3435]
Path:            /Applications/Easydict.app/Contents/MacOS/Easydict
Identifier:      com.izual.Easydict
Version:         2.10.0 (40)
Code Type:       arm64
Parent Process:  launchd [1]

Date/Time:       2024-11-09T03:16:53.999Z
Launch Time:     2024-11-08T06:29:26Z
OS Version:      Mac OS X 15.0.1 (24A348)
Report Version:  104

Exception Type:  SIGABRT
Exception Codes: #0 at 0x19763e600
Crashed Thread:  3

Thread 3 Crashed:
0   libsystem_kernel.dylib               0x000000019763e600 __pthread_kill + 8
1   libsystem_c.dylib                    0x0000000197583908 abort + 124
2   libsystem_malloc.dylib               0x000000019748d67c malloc_vreport + 892
3   libsystem_malloc.dylib               0x000000019749123c malloc_report + 60
4   libsystem_malloc.dylib               0x00000001974af26c find_zone_and_free + 524
5   CoreFoundation                       0x00000001976fe448 -[__NSArrayM insertObject:atIndex:] + 364
6   AppKit                               0x000000019b34cb34 -[NSPasteboard _updateTypeCacheIfNeeded] + 700
7   AppKit                               0x000000019b34c7b8 -[NSPasteboard _typesAtIndex:combinesItems:] + 32
8   Easydict                             0x00000001007f33c0 (extension in SelectedTextKit):__C.NSPasteboard.saveCurrentContents() -> () (NSPasteboard+Extension.swift:36)
9   Easydict                             0x00000001007f4c08 $s15SelectedTextKit24getNextPasteboardContent11triggeredBy08preserveF0SSSgyyKc_SbtYaF04$s15ab12Kit03getaB14I26ShortcutCopySSSgyYaFyycfU_Tf1cn_nTY1_ (NSPasteboard+Extension.swift:19)
10  libswift_Concurrency.dylib           0x0000000270e14400 swift::runJobInEstablishedExecutorContext(swift::Job*) + 248
11  libswift_Concurrency.dylib           0x0000000270e157a4 swift_job_runImpl(swift::Job*, swift::SerialExecutorRef) + 140
12  Easydict                             0x0000000100b39f1c NIOPosix.SelectableEventLoop.(runLoop in _F063900CF099EAD3573B5A801BBBAFDC)(selfIdentifier: Swift.ObjectIdentifier) -> NIOCore.NIODeadline? (<compiler-generated>:0)
13  Easydict                             0x0000000100b3806c NIOPosix.SelectableEventLoop.run() throws -> () (SelectableEventLoop.swift:718)
14  Easydict                             0x0000000100b16c68 function signature specialization <Arg[6] = Dead, Arg[7] = Owned To Guaranteed, Arg[8] = Owned To Guaranteed> of function signature specialization <Arg[6] = [Closure Propagated : closure #1 (NIOPosix.SelectableEventLoop) -> () in closure #1 (NIOPosix.NIOThread) -> () in static NIOPosix.MultiThreadedEventLoopGroup.(setupThreadAndEventLoop in _C2B1528F4FBA68A3DBFA89DBAEBE9D4D)(name: Swift.String, parentGroup: NIOPosix.MultiThreadedEventLoopGroup, selectorFactory: () throws -> NIOPosix.Selector<NIOPosix.NIORegistration>, initializer: (NIOPosix.NIOThread) -> (), metricsDelegate: Swift.Optional<NIOPosix.NIOEventLoopMetricsDelegate>) -> NIOPosix.SelectableEventLoop, Argument Types : [NIOConcurrencyHelpers.ConditionLock<Swift.Int>{ var NIOPosix.SelectableEventLoop? }]> of static NIOPosix.MultiThreadedEventLoopGroup.(runTheLoop in _C2B1528F4FBA68A3DBFA89DBAEBE9D4D)(thread: NIOPosix.NIOThread, parentGroup: NIOPosix.MultiThreadedEventLoopGroup?, canEventLoopBeShutdownIndividually: Swift.Bool, selectorFactory: () throws -> NIOPosix.Selector<NIOPosix.NIORegistration>, initializer: (NIOPosix.NIOThread) -> (), metricsDelegate: NIOPosix.NIOEventLoopMetricsDelegate?, _: (NIOPosix.SelectableEventLoop) -> ()) -> () (MultiThreadedEventLoopGroup.swift:95)
15  Easydict                             0x0000000100b14698 closure #1 (NIOPosix.NIOThread) -> () in static NIOPosix.MultiThreadedEventLoopGroup.(setupThreadAndEventLoop in _C2B1528F4FBA68A3DBFA89DBAEBE9D4D)(name: Swift.String, parentGroup: NIOPosix.MultiThreadedEventLoopGroup, selectorFactory: () throws -> NIOPosix.Selector<NIOPosix.NIORegistration>, initializer: (NIOPosix.NIOThread) -> (), metricsDelegate: NIOPosix.NIOEventLoopMetricsDelegate?) -> NIOPosix.SelectableEventLoop (<compiler-generated>:0)
16  Easydict                             0x0000000100b17b18 partial apply forwarder for closure #1 (NIOPosix.NIOThread) -> () in static NIOPosix.MultiThreadedEventLoopGroup.(setupThreadAndEventLoop in _C2B1528F4FBA68A3DBFA89DBAEBE9D4D)(name: Swift.String, parentGroup: NIOPosix.MultiThreadedEventLoopGroup, selectorFactory: () throws -> NIOPosix.Selector<NIOPosix.NIORegistration>, initializer: (NIOPosix.NIOThread) -> (), metricsDelegate: NIOPosix.NIOEventLoopMetricsDelegate?) -> NIOPosix.SelectableEventLoop (<compiler-generated>:0)
17  Easydict                             0x00000001006f7068 $s5Vapor11ApplicationCAA5Cache_pIeghgr_AcaD_pIeghnr_TR (<compiler-generated>:0)
18  Easydict                             0x0000000100b53678 closure #1 (Swift.UnsafeMutableRawPointer) -> Swift.UnsafeMutableRawPointer? in static NIOPosix.ThreadOpsPosix.run(handle: inout Swift.UnsafeMutablePointer<__C._opaque_pthread_t>?, args: NIOPosix.Box<(body: (NIOPosix.NIOThread) -> (), name: Swift.String?)>, detachThread: Swift.Bool) -> () (ThreadPosix.swift:116)
19  libsystem_pthread.dylib              0x00000001976772e4 _pthread_start + 132
20  libsystem_pthread.dylib              0x00000001976720fc thread_start + 4

@tisfeng
Copy link
Owner

tisfeng commented Nov 9, 2024

找到原因就好办了,写个测试方法,多次运行测试可稳定复现该问题。

复现条件

执行 testGetSelectedText() 时,多次选中一些不支持 Accessibility 取词的文本,例如 Xcode 右侧的文档区域,此时 getSelectedText() 方法会调用菜单栏动作取词,或快捷键辅助取词,这时大概率会出现崩溃。

问题原因

菜单栏动作取词和快捷键辅助取词,都依赖于系统剪贴板,而 NSPasteboard 不是线程安全的,之前使用 async/await 重构了取词功能,没考虑到多线程。

如何解决

使用 @MainActor,将 NSPasteboard 相关的读写操作放到主线程。 fix: make sure call NSPasteboard in main thread

@Test func testGetSelectedText() async {
    // Run thousands of times to test crash.
    for i in 0..<2000 {
        print("test index: \(i)")
        let selectedText = await (try? getSelectedText()) ?? ""
        print("\(i) selectedText: \(selectedText)")
    }
}
image

@tisfeng tisfeng added the fixed in next release The issue will be closed once next release is available label Nov 9, 2024
@tisfeng
Copy link
Owner

tisfeng commented Nov 9, 2024

我在 dev 更新了 SelectedTextKit 版本 27551af ,现在 Easydict 应该已修复了。

@phlpsong @Jerry23011 请确认一下这个问题,如果要复现,可以将测试代码 e55735f pick 到 089320e 节点。

如果确认修复了,明天我们就发个修复版本。

@phlpsong
Copy link
Collaborator

phlpsong commented Nov 9, 2024

我测试了最新的dev和089320e 节点, 看起来两个test case都正常通过。

@Jerry23011
Copy link
Collaborator

Jerry23011 commented Nov 10, 2024

我这边也测试了最新dev和089320e 两个 test 通过,但是 checkout 到2.10.0 的 release(246e44d)两个test还是都可以通过,并不能复现问题

@tisfeng
Copy link
Owner

tisfeng commented Nov 10, 2024

执行 testGetSelectedText() 时,多次选中一些不支持 Accessibility 取词的文本,例如 Xcode 右侧的文档区域,此时 getSelectedText() 方法会调用菜单栏动作取词,或快捷键辅助取词,这时大概率会出现崩溃。

你测过强制取词吗? 只运行测试用例不行,默认会进行 Accessibility 取词,这个本身就没问题,你还需要同时进行强制取词,并且多次不断选中,取消,然后选中。

@lemesevkirill
Copy link

lemesevkirill commented Nov 10, 2024

can't read your language guys, but I have the same issue! random crashes. I can't post issues to this account somehow. Here is my log
Easydict log 2024-11-10 14-17-14-670.zip

@phlpsong
Copy link
Collaborator

phlpsong commented Nov 10, 2024

打开强制取词后,测试testGetSelectedText 同时选择Xcode 文档区域 确实会crash。最新的dev测试正常。

@tisfeng
Copy link
Owner

tisfeng commented Nov 10, 2024

2.10.1 版本已修复了该问题,请更新。

Version 2.10.1 has fixed the issue, please update.

@tisfeng tisfeng closed this as completed Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next release The issue will be closed once next release is available
Projects
None yet
Development

No branches or pull requests

9 participants