gizmo385 / discord.clj

A Clojure library for creating Discord bots
MIT License
45 stars 14 forks source link

Heartbeat loop isn't halted along with the gateway #3

Closed codonnell closed 6 years ago

codonnell commented 6 years ago

After closing the gateway (and its websocket), the heartbeat loop continues running, resulting in this error a bit afterwards:

Exception in thread "async-dispatch-9" org.eclipse.jetty.websocket.api.WebSocketException: RemoteEndpoint unavailable, current state [CLOSED], expecting [OPEN or CONNECTED]
        at org.eclipse.jetty.websocket.common.WebSocketSession.getRemote(WebSocketSession.java:299)
        at gniazdo.core$connect_with_client$reify__20760.send_msg(core.clj:138)
        at discord.gateway.DiscordGateway.send_message(gateway.clj:62)
        at discord.gateway$send_heartbeat.invokeStatic(gateway.clj:205)
        at discord.gateway$send_heartbeat.invoke(gateway.clj:203)
        at discord.gateway$connect_to_gateway$fn__25400$state_machine__13838__auto____25417$fn__25419.invoke(gateway.clj:292)
        at discord.gateway$connect_to_gateway$fn__25400$state_machine__13838__auto____25417.invoke(gateway.clj:292)
        at clojure.core.async.impl.ioc_macros$run_state_machine.invokeStatic(ioc_macros.clj:973)
        at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:972)
        at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invokeStatic(ioc_macros.clj:977)
        at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:975)
        at clojure.core.async.impl.ioc_macros$take_BANG_$fn__13856.invoke(ioc_macros.clj:986)
        at clojure.core.async.impl.channels.ManyToManyChannel$fn__8788.invoke(channels.clj:265)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

I'm happy to submit a PR fixing this if you'd like.

gizmo385 commented 6 years ago

@codonnell Great catch! If you've already got a fix for the issue, feel free to throw up a PR for it! I can probably take a look at the issue this evening or tomorrow. Thanks for submitting the issue!

codonnell commented 6 years ago

PR up with a fix at https://github.com/gizmo385/discord.clj/pull/4. I'm happy to make adjustments if needed. Thanks for responding promptly!

gizmo385 commented 6 years ago

This has been fixed by @codonnell in #4. Thanks for the fix!