Kord does not recover from UnknownHostException
It seems like Kord doesn't recover from
UnknownHostException
- at least not fully as the Discord bot appears as offline
and does no longer react to application commands until it is restarted. I ran into this issue two times in the past few weeks. The bot is using google dns to resolve hostnames.
Stack trace is attached as screenshot since... discord message character limit...
Also, here's the project in case you want to look something up: https://github.com/DarkAtra/v-rising-discord-bot
20 Replies
Would you like to it to retry after an UnknownHostException? I think it's intended, that it doesn't recover from name resulution issues, as the indicate a persistent problem
Yes, I would expect Kord to attempt to recover in such a case. In my experience, most
UnknownHostException
are temporary and usually recoverable by retrying with backoff.
is there any way for me to force gateway reconnects when an UnknownHostException occurs for the time being?
@SchlaubiBus any idea?I don't think there is a way
The same issue just happened again today at around 1am. My bot was unable to resolve the hostname
gateway-us-east1-b.discord.gg
for about 2 minutes (using google DNS).
I thought about switching the dns provider that ok-http uses from system
(google dns) to something else. However, this could still fail since there is no guarantee that DNS lookups always succeed. I think the only way of dealing with this issue permantently is to make kord more resilient and attempt reconnects with backoff.
Right now it's getting stuck in a weird state where it can query and update messages in a discord server but doesn't react to application commands anymore.When does this happen, because it wouldn't make sense for this to happen during a connection
The cause likely is:
I men that's just internal code of okhttp
discord message length fucked up the stack trace - i've updated it.
it's still just okhttp
this is the disconnect from the gateway and then kord attempts to reconnect right after - this is where the hostname exception occurs
I don't see that in that error
correct me if i'm wrong but this is how i understand the gateway connection:
There is a websocket connection that kord uses to receive events from discord - for example for command issued by users on a server.
When this websocket connection is closed by the peer for whatever reason, kord attempts to reconnect to the gateway.
Now if the hostname of the gateway could not be resolved - the attempt is aborted and kord never reconnects.
i cant post the full stack trace as i dont have nitro. the logs reads:
You can upload them as a file?
This is the reconnect code

the errors are 8 minutes apart tho.. so yeah not sure if they are related
There should be more logs about retrying
nope, nothing else besides the two errors i just sent you. The
UnknownHostException
reoccurs like 20 times or so thoThen you need to increase the log level
ok, i'll set it to trace for kord and report back when it happens again