"Anki Quit Unexpectedly" Error when closing Anki

I believe this is similar to this thread here

Seems to happen when just opening Anki, going into Browse, then quitting the app. No add-ons enabled.

Here is the first ~100 lines of code:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               anki [29041]
Path:                  /Applications/Anki.app/Contents/MacOS/anki
Identifier:            net.ankiweb.dtop
Version:               2.1.55 (???)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2022-12-23 02:08:17.3248 -0500
OS Version:            macOS 12.3.1 (21E258)
Report Version:        12
Anonymous UUID:        7613D848-9E20-2A66-42AE-54FD194B6986

Sleep/Wake UUID:       319F421E-F156-4A2A-B01E-3FDAA625D6EC

Time Awake Since Boot: 76000 seconds
Time Since Wake:       1164 seconds

System Integrity Protection: enabled

Crashed Thread:        0  CrBrowserMain  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x00009bc496b76ef8 -> 0x00001bc496b76ef8 (possible pointer authentication failure)
Exception Codes:       0x0000000000000001, 0x00009bc496b76ef8
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [29041]

VM Region Info: 0x1bc496b76ef8 is not in any region.  Bytes after previous region: 30050119806713  Bytes before following region: 75021960122632
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      commpage (reserved)        1000000000-7000000000   [384.0G] ---/--- SM=NUL  ...(unallocated)
--->  GAP OF 0x5f9000000000 BYTES
      MALLOC_NANO              600000000000-600008000000 [128.0M] rw-/rwx SM=PRV  

Kernel Triage:
VM - pmap_enter failed with resource shortage
VM - pmap_enter failed with resource shortage
VM - pmap_enter failed with resource shortage
VM - pmap_enter failed with resource shortage
VM - pmap_enter failed with resource shortage


Thread 0 Crashed:: CrBrowserMain Dispatch queue: com.apple.main-thread
0   QtWebEngineCore               	       0x13a362c8c 0x13a328000 + 240780
1   QtWebEngineCore               	       0x13a362c88 0x13a328000 + 240776
2   QtWebEngineCore               	       0x13c90a8b0 0x13a328000 + 39725232
3   QtWebEngineCore               	       0x13de46428 0x13a328000 + 61989928
4   QtWebEngineCore               	       0x13de442a0 0x13a328000 + 61981344
5   QtWebEngineCore               	       0x13c90652c 0x13a328000 + 39707948
6   QtWebEngineCore               	       0x13c907078 0x13a328000 + 39710840
7   QtWebEngineCore               	       0x13cd382fc 0x13a328000 + 44106492
8   QtWebEngineCore               	       0x13c91159c 0x13a328000 + 39753116
9   QtWebEngineCore               	       0x13d8e4ea8 0x13a328000 + 56348328
10  QtWebEngineCore               	       0x13d8e95f4 0x13a328000 + 56366580
11  QtWebEngineCore               	       0x13d8b27f8 0x13a328000 + 56141816
12  QtWebEngineCore               	       0x13d8c884c 0x13a328000 + 56232012
13  QtWebEngineCore               	       0x13d8c85b8 0x13a328000 + 56231352
14  QtWebEngineCore               	       0x13a366160 0x13a328000 + 254304
15  QtCore                        	       0x10821b350 QObject::event(QEvent*) + 88
16  QtWidgets                     	       0x10b4e5c90 QApplicationPrivate::notify_helper(QObject*, QEvent*) + 272
17  QtWidgets                     	       0x10b4e6cf8 QApplication::notify(QObject*, QEvent*) + 512
18  QtWidgets.abi3.so             	       0x10bbdce04 sipQApplication::notify(QObject*, QEvent*) + 248
19  QtCore                        	       0x1081d9d40 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 208
20  QtCore                        	       0x1081daf84 QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) + 808
21  libqcocoa.dylib               	       0x10d5c7cb4 0x10d5b0000 + 97460
22  libqcocoa.dylib               	       0x10d5c8344 0x10d5b0000 + 99140
23  CoreFoundation                	       0x18e6e29a0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
24  CoreFoundation                	       0x18e6e28ec __CFRunLoopDoSource0 + 208
25  CoreFoundation                	       0x18e6e25ec __CFRunLoopDoSources0 + 268
26  CoreFoundation                	       0x18e6e0f6c __CFRunLoopRun + 828
27  CoreFoundation                	       0x18e6e0490 CFRunLoopRunSpecific + 600
28  HIToolbox                     	       0x197300dd8 RunCurrentEventLoopInMode + 292
29  HIToolbox                     	       0x197300b54 ReceiveNextEventCommon + 564
30  HIToolbox                     	       0x197300908 _BlockUntilNextEventMatchingListInModeWithFilter + 72
31  AppKit                        	       0x19123fb2c _DPSNextEvent + 860
32  AppKit                        	       0x19123e424 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1328
33  AppKit                        	       0x1912305f0 -[NSApplication run] + 596
34  libqcocoa.dylib               	       0x10d5c722c 0x10d5b0000 + 94764
35  QtCore                        	       0x1081e339c QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 544
36  QtCore                        	       0x1081da3f4 QCoreApplication::exec() + 128
37  QtWidgets.abi3.so             	       0x10bce22b4 meth_QApplication_exec(_object*, _object*) + 96
38  anki                          	       0x1007c0c8c cfunction_call + 104
39  anki                          	       0x10077a1e8 _PyObject_MakeTpCall + 136
40  anki                          	       0x10087aa74 _PyEval_EvalFrameDefault + 23972
41  anki                          	       0x10077b470 _PyFunction_Vectorcall + 720
42  anki                          	       0x100878d00 _PyEval_EvalFrameDefault + 16432
43  anki                          	       0x10077b290 _PyFunction_Vectorcall + 240
44  anki                          	       0x100879bf0 _PyEval_EvalFrameDefault + 20256
45  anki                          	       0x10087e0b4 _PyEval_EvalCode + 532
46  anki                          	       0x100874bcc PyEval_EvalCode + 80
47  anki                          	       0x1008c8be4 run_mod + 152
48  anki                          	       0x1008c8140 PyRun_StringFlags + 152
49  anki                          	       0x1008c8064 PyRun_SimpleStringFlags + 64
50  anki                          	       0x1006dc224 Py_RunMain + 340
51  anki                          	       0x1003ce7e4 pyembed::interpreter::MainPythonInterpreter::run::hf7673bad7bf3689d + 204
52  anki                          	       0x1003c4980 anki::main::hd27d0a6c8575a48d + 1080
53  anki                          	       0x1003c4bac std::sys_common::backtrace::__rust_begin_short_backtrace::h42c5a5f5815c12f1 + 12
54  anki                          	       0x1003c4010 std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h9fb6193599b5fa96 + 16
55  anki                          	       0x100d78454 std::rt::lang_start_internal::h94fa211da9d06d56 + 580
56  anki                          	       0x1003c4b94 main + 52
57  dyld                          	       0x103e3d088 start + 516

Thread 1:
0   libsystem_pthread.dylib       	       0x18e611078 start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib       	       0x18e611078 start_wqthread + 0

Thread 3:
0   libsystem_pthread.dylib       	       0x18e611078 start_wqthread + 0

Thread 4:: com.apple.CFSocket.private
0   libsystem_kernel.dylib        	       0x18e5e35b8 __select + 8
1   CoreFoundation                	       0x18e70d1fc __CFSocketManager + 644
2   libsystem_pthread.dylib       	       0x18e61626c _pthread_start + 148
3   libsystem_pthread.dylib       	       0x18e61108c thread_start + 8

It appears to be a bug either in the web toolkit, or macOS. You could try updating macOS to see if it helps. After mid Jan we can try updating to a new toolkit version, which may also help.

Upgraded to macOS 13.1.

I first tested Anki 3 times, just by doing some reviews, going into Browser, and changing the deck for a card, etc. Nothing crashed those times, and my add-ons were turned OFF from the last time of use.

On the 4th time, I turned on my add-ons and then quit Anki, and I got the crash again. So I turned off the add-ons and did some review then exited… and I still got the crash. Now I keep getting subsequent crashes.

I wonder if activating add-ons is somehow causing a memory problem for macOS, and it’s stuck in that state, but honestly I’m probably far off.

Also, Shift-click Anki does not produce this crash

It is possible there is some sort of resource leak in macOS that is triggering it. Further experimentation may reveal more - for example if after the 3 times without add-ons you continued to avoid add-ons, I wonder whether the issue would crop up again after enough time, or if it would be gone for good?

1 Like

I will definitely be willing to try that, but I don’t know how to get back to a state of non-crashing. If there is another macOS update, I’ll be sure to leave the add-ons off, update, then test Anki for ~10 days without turning them back on; and I’ll report back

If it’s a resource leak, restarting the computer should bring you back to a baseline.

It might not be then, since I did restart and I still got the error. I also switched to RC2 and still got the error (but actually I don’t know if these are the same build).

You said above that turning off your add-ons doesn’t prevent the problem from happening, but you say that shift+click does. If that’s the case, what happens if you disable automatic syncing in the preferences and restart without holding down the shift key?

After setting “Automatically sync on profile open/close” to OFF
(and leaving ON “Synchronize audio and images too” and “Periodically sync media”),
I have found that I no longer get the error with regular (non shift-click) open and closing.
Still worked even after re-enabling my regular add-ons.

If you need me to do any more syncing testing, let me know

Unfortunately I can’t seem to reproduce the issue. If you create a ‘test’ folder inside your add-on folder, and put the following inside __init__.py in the folder, does it make any difference?

from __future__ import annotations

from concurrent.futures import Future
from typing import Callable

from aqt.qt import *


def with_progress(
    self,
    task: Callable,
    on_done: Callable[[Future], None] | None = None,
    parent: QWidget | None = None,
    label: str | None = None,
    immediate: bool = False,
) -> None:
    "Use QueryOp()/CollectionOp() in new code."
    self.mw.progress.start(parent=parent, label=label, immediate=False)

    def wrapped_done(fut: Future) -> None:
        self.mw.progress.finish()
        if on_done:
            on_done(fut)

    self.run_in_background(task, wrapped_done)


from aqt.taskman import TaskManager

TaskManager.with_progress = with_progress

If not, what about the following, which will hide the progress window completely (so you won’t be able to see that it’s syncing)?

from __future__ import annotations

from concurrent.futures import Future
from typing import Callable

from aqt.qt import *


def with_progress(
    self,
    task: Callable,
    on_done: Callable[[Future], None] | None = None,
    parent: QWidget | None = None,
    label: str | None = None,
    immediate: bool = False,
) -> None:
    "Use QueryOp()/CollectionOp() in new code."
    # self.mw.progress.start(parent=parent, label=label, immediate=False)
    self.mw.progress._shown = False

    def wrapped_done(fut: Future) -> None:
        # self.mw.progress.finish()
        if on_done:
            on_done(fut)

    self.run_in_background(task, wrapped_done)


from aqt.taskman import TaskManager

TaskManager.with_progress = with_progress

Very strange. Using the first or second code block inside __init__.py and leaving the automatic sync option off, there was no crashes.

When I turned on the automatic syncing there were crashes again. Except that now they have stopped after a while of testing. What I noticed mostly was that the crashes happened when the “media sync” box didn’t appear when closing Anki. But when it did pop up, I didn’t get any crashes. (except when I closed Anki quickly from it starting, like within 1-2 second of opening)

There have been a few different errors, so I am trying to do more testing to see what causes these and give my thoughts.

I presume it doesn’t happen in the Qt5 version? At this point our best bet may be to hope that it gets resolved in the next toolkit update.

It still happens in the Qt5 version (Intel version). I’ve also tried it with the new Beta (2.1.56 RC1).

Here’s another error report:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               anki [78598]
Path:                  /Applications/Anki.app/Contents/MacOS/anki
Identifier:            net.ankiweb.dtop
Version:               2.1.55 (???)
Code Type:             X86-64 (Translated)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2023-01-05 02:17:43.0318 -0500
OS Version:            macOS 13.1 (22C65)
Report Version:        12
Anonymous UUID:        7613D848-9E20-2A66-42AE-54FD194B6986

Sleep/Wake UUID:       F3DAF44A-83C5-442B-9A5D-5F0AA2BA10BA

Time Awake Since Boot: 140000 seconds
Time Since Wake:       877 seconds

System Integrity Protection: enabled

Crashed Thread:        0  CrBrowserMain  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x700007fc54c2dddd -> 0x000007fc54c2dddd (possible pointer authentication failure)
Exception Codes:       0x0000000000000001, 0x700007fc54c2dddd

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [78598]

VM Region Info: 0x7fc54c2dddd is not in any region.  Bytes after previous region: 8299298872798  Bytes before following region: 131704520778275
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      commpage (reserved)        1000000000-7000000000   [384.0G] ---/--- SM=NUL  ...(unallocated)
--->  GAP OF 0x7f552df00000 BYTES
      MALLOC_TINY              7fc52df00000-7fc52e000000 [ 1024K] rw-/rwx SM=PRV  

Kernel Triage:
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage


Thread 0 Crashed:: CrBrowserMain Dispatch queue: com.apple.main-thread
0   <translation info unavailable>	       0x108fd0880 ???
1   QtWebEngineCore               	       0x130f7fd92 0x12ca98000 + 72252818
2   libsystem_platform.dylib      	    0x7ff81b477c33 _sigtramp + 51
3   QtWebEngineCore               	       0x12f7d0a8c 0x12ca98000 + 47417996
4   QtWebEngineCore               	       0x130f90f01 0x12ca98000 + 72322817
5   QtWebEngineCore               	       0x130f8e963 0x12ca98000 + 72313187
6   QtWebEngineCore               	       0x12f7cc2d5 0x12ca98000 + 47399637
7   QtWebEngineCore               	       0x12f7ccefb 0x12ca98000 + 47402747
8   QtWebEngineCore               	       0x12fc8fce2 0x12ca98000 + 52395234
9   QtWebEngineCore               	       0x12f7d8b37 0x12ca98000 + 47450935
10  QtWebEngineCore               	       0x130993d96 0x12ca98000 + 66043286
11  QtWebEngineCore               	       0x130998759 0x12ca98000 + 66062169
12  QtWebEngineCore               	       0x13095c689 0x12ca98000 + 65816201
13  QtWebEngineCore               	       0x13097528f 0x12ca98000 + 65917583
14  QtWebEngineCore               	       0x130974fca 0x12ca98000 + 65916874
15  QtWebEngineCore               	       0x130975812 0x12ca98000 + 65918994

That’s interesting. I’ve logged this on Sporadic crashes when shutting down application · Issue #2299 · ankitects/anki · GitHub

I’ve again disabled the automatic sync option, and no sporadic errors.

I have tried to manually close Anki while it is syncing, and I do indeed get the error. Usually I will manually sync and wait a few seconds for it to finish and then close, and it will work fine.

However, when I do close it during the sync, specifically during when the black box pops up (“media sync” I believe), then I get the error again. And also, on the reopen of Anki, the sync button on the top right is still blue (i.e. it didn’t sync yet), so there is an interruption.

So my guess at a solution would be to add some delay to the auto-closing of Anki when the sync is finished, or something to that effect

I’m not sure how helpful macOS error reports are:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               anki [52231]
Path:                  /Applications/Anki.app/Contents/MacOS/anki
Identifier:            net.ankiweb.dtop
Version:               2.1.57 (???)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2023-01-19 00:23:41.1256 -0500
OS Version:            macOS 13.1 (22C65)
Report Version:        12
Anonymous UUID:        7613D848-9E20-2A66-42AE-54FD194B6986

Sleep/Wake UUID:       F38CB5E4-1756-441D-BBCE-C13A97289BC7

Time Awake Since Boot: 380000 seconds
Time Since Wake:       6 seconds

System Integrity Protection: enabled

Crashed Thread:        0  CrBrowserMain

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes:       0x0000000000000001, 0x0000000000000000

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [52231]

VM Region Info: 0 is not in any region.  Bytes before following region: 4298604544
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      100378000-103220000    [ 46.7M] r-x/r-x SM=COW  ...ts/MacOS/anki

Kernel Triage:
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage


Thread 0 Crashed:: CrBrowserMain
0   ???                           	               0x0 ???
1   QtWebEngineCore               	       0x11bffa8b0 0x119a18000 + 39725232
2   QtWebEngineCore               	       0x11d536428 0x119a18000 + 61989928
3   QtWebEngineCore               	       0x11d5342a0 0x119a18000 + 61981344
4   QtWebEngineCore               	       0x11bff652c 0x119a18000 + 39707948
5   QtWebEngineCore               	       0x11bff7078 0x119a18000 + 39710840
6   QtWebEngineCore               	       0x11c4282fc 0x119a18000 + 44106492
7   QtWebEngineCore               	       0x11c00159c 0x119a18000 + 39753116
8   QtWebEngineCore               	       0x11cfd4ea8 0x119a18000 + 56348328
9   QtWebEngineCore               	       0x11cfd95f4 0x119a18000 + 56366580

I think we have enough reports for this one already :slight_smile:

Subscribed

Dear @blackace72 it is similar to my problem (I know I’m a bit late to the party)!

I’m not sure what is the state of the fixing - what I do when the crashing happens is I uninstall/delete ANKI and install again, and it works for a while without issue. I cannot pinpoint what causes the crashes.

I’m going to watch this thread to see if you find the root cause of the problem!

@rudygosia ,

My short term solution is this:

  • Go here: Preferences/Settings → Syncing
  • Turn Automatically sync on profile open/close to OFF

When I did this, I don’t have the problem anymore.

Can you try this same settings, and tell me if you continue to get the error. Thank you.