sleepy-discord icon indicating copy to clipboard operation
sleepy-discord copied to clipboard

Crash on quit

Open TylerTheFox opened this issue 6 years ago • 22 comments

I downloaded the latest from the Develop branch and now it crashes on quit().

image image image

[2018-05-29 02:17:53] [warning] got non-close frame while closing [2018-05-29 02:17:53] [warning] got non-close frame while closing [2018-05-29 02:17:53] [error] handle_read_frame error: asio.ssl.stream:1 (stream truncated) [2018-05-29 02:17:53] [info] asio async_shutdown error: asio.ssl.stream:1 (stream truncated) [2018-05-29 02:17:53] [disconnect] Disconnect close local:[1006,stream truncated] remote:[1000]

TylerTheFox avatar May 29 '18 09:05 TylerTheFox

It's hard to say what's causing the crash. What I can see is that it looks like you are using mode USE_RUN_THREAD. Which to be honest, I haven't used in like forever. The run thread is used for scheduling events and websocket connections. I'm not sure if you really need this thread but try using USER_CONTROLED_THREADS, do not that this isn't documented just yet but the example have already been updated if you need examples.

yourWaifu avatar May 29 '18 15:05 yourWaifu

I dont need any threads I didn't change anything. I clicked build on visual studio after downloading develop.

Unless you mean this https://github.com/Brandantl/Monero-TipBot/blob/master/src/main.cpp#L120

Which I copied and paste from an example I think

TylerTheFox avatar May 29 '18 17:05 TylerTheFox

change

TIPBOT client(GlobalConfig.General.discordToken, 2);

to

TIPBOT client(GlobalConfig.General.discordToken, SleepyDiscord::USER_CONTROLED_THREADS);

Sorry about this, I noticed that a number of users were getting confused about the number so I changed it. I must of changed to the number to better represent how many threads are actually being used.

I'll document this change in the docs. Thanks for reminding me.

yourWaifu avatar May 29 '18 18:05 yourWaifu

Same issue on the destructor of WebsocketppDiscordClient

TylerTheFox avatar May 30 '18 06:05 TylerTheFox

image image

TylerTheFox avatar May 30 '18 06:05 TylerTheFox

I just reverted to the last known working version I had compiled. It's broken on the most recent sleepy discord though.

TylerTheFox avatar May 30 '18 09:05 TylerTheFox

I have actually recently ran into this issue, it seems to happen randomly on a bad connection. This one is going to a hard issue to debug if that's the case.

yourWaifu avatar Jun 20 '18 03:06 yourWaifu

So the quit() is functioning correctly but when the class destructs afterwards it crashes in the WebsocketppDiscordClient destructor.

We cleanly exited the sleepy discord run() function here (which is what Tbot.start(); does)

image

I think there is an issue with the order in which the destructors are working or that _thread isn't being set to nullptr after quit() is invoked and the threads are shutdown. It reads 0xcccccccc

image

TylerTheFox avatar Jul 12 '18 05:07 TylerTheFox

(((SleepyDiscord::WebsocketppDiscordClient)&(((Discord)&Tbot))))._thread

is NEVER initialized in the life time of the application.

That's your issue. _threads is never initialized to nullptr therefore undefined behavior occurs on shutdown.

TylerTheFox avatar Jul 12 '18 05:07 TylerTheFox

actually that makes sense, most of the time, it does nothing unless you asked for more threads. I can't remember why reset is being called since that was written so long ago.

yourWaifu avatar Jul 12 '18 05:07 yourWaifu

This still exists and is kind of annoying because I need my bot to clean exit on shutdown. image

image

image

It does it now on Linux and Windows and only when sleepy discord is enabled.

TylerTheFox avatar Aug 10 '18 22:08 TylerTheFox

Even crashes on exit with this code image

Attached to this comment is the compilable code. Discord-Test.zip

TylerTheFox avatar Aug 10 '18 22:08 TylerTheFox

I'm actually currently making some changes to quit that should hopefully fix this issue. I think it should be finished by tomorrow.

yourWaifu avatar Aug 10 '18 22:08 yourWaifu

No problem I was trying to find it using my commercial memory checkers and couldn't locate it for some reason. I'll check with valgrind to see if i can pinpoint it.

TylerTheFox avatar Aug 10 '18 22:08 TylerTheFox

Nope couldn't figure it out. I'll test it again once you refactor quit() and the shutdown process. image

TylerTheFox avatar Aug 10 '18 23:08 TylerTheFox

Stack corruption still occurs on https://github.com/yourWaifu/sleepy-discord/commit/325e770b2eb6602a8312b38bff6ba6e099b307dd image

TylerTheFox avatar Aug 11 '18 02:08 TylerTheFox

I did some testing and found that adding the predecessor define SLEEPY_VOICE_ENABLED fixes this, and this is why I wasn't getting this error. I'll see what SLEEPY_VOICE_ENABLED has to do with this issue.

yourWaifu avatar Aug 11 '18 05:08 yourWaifu

G++ won't allow you to compile because of a local being returned from a reference function. image

TylerTheFox avatar Aug 11 '18 05:08 TylerTheFox

you can remove that function, it's not used nor does it work. I also thought I removed it.

yourWaifu avatar Aug 11 '18 06:08 yourWaifu

Ok nevermind, it is used. I'll have to fix that

yourWaifu avatar Aug 11 '18 06:08 yourWaifu

The issue still occurs on builds without SLEEPY_VOICE_ENABLED image

and this happens with SLEEPY_VOICE_ENABLED image

TylerTheFox avatar Aug 12 '18 01:08 TylerTheFox

Yup I can confirm now that SLEEPY_VOICE_ENABLED compiles that it does not occur with that define. I'll test it on Windows in a bit to see if that CRT error still occurs.

image

TylerTheFox avatar Aug 12 '18 03:08 TylerTheFox