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

Fix worker thread memory leaks (solves error 2011-0301, threadCreate rc 559) #27

Merged
merged 1 commit into from
Nov 23, 2019

Conversation

RattletraPM
Copy link
Contributor

@RattletraPM RattletraPM commented Nov 22, 2019

The crashes happened due to a memory leak related to the sysmodule's worker threads. When exiting one of the said threads, ldn_mitm erroneously calls svcExitThread before workerThread.Join which makes the latter fail to exit cleanly and free is resources (return code 5977) and that causes the aforementioned leak. After some time, the sysmodule runs out of free memory and, thus, it becomes unable to create new worker threads (threadCreate return code 559, aka LibnxError_OutOfMemory). That's why you must reset the console once it crashes to make it work again.

Unless I misunderstood what the code does, calling svcExitThread shouldn't be needed at all because Join already waits for a thread to be done executing and then terminates it cleanly (in a nutshell, it first calls threadWaitForExit and then threadClose) so all this mod does is it just removes the svcExitThread call - so far, I haven't seen any adverse effects by doing so after around 24 hours of mixed online gameplay/idling, nor any Join/threadCreate errors in the logs. An issue like this wouldn't be limited to Pokémon only and old logs seem to confirm it, however, the crashes likely only popped up now because Pokémon sends a metric crapton of stuff over the network compared to the other Switch games, thus exhausting the available memory more quickly.

(Quoted from my post here on the temp. Other people have reported no issues too since then.)

@RattletraPM RattletraPM changed the title Fix worker thread memory leaks (solves Sword/Shield error 2011-0301, threadCreate rc 559) Fix worker thread memory leaks (solves error 2011-0301, threadCreate rc 559) Nov 23, 2019
@RattletraPM
Copy link
Contributor Author

RattletraPM commented Nov 23, 2019

Title got edited to picture the issue in a more generic way.

@spacemeowx2
Copy link
Owner

Thanks! I will review this pr when I get home

@spacemeowx2 spacemeowx2 merged commit 495d565 into spacemeowx2:master Nov 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants