-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
v3: Gateway reconnect panic #286
Comments
What's your code for this? The library should already be handling reconnection. FWIW, that is eventually going to be refactored to be completely thread-safe, |
Yes, for every "session", if This is because reconnection is not working well in my experience, if I see something like "going away" or "requested to reconnect", IIRC it hangs indefinitely, simply close it and create a new state solved it. func session (sCloser chan struct{}) (err error) {
var sessionSelfCloser chan struct{} = make(chan struct{})
logger.Logger.Infof("[MAIN] Session is starting...")
sv, err = storage.Sqlite()
if err != nil {
return errors.Wrap(err, "Failed to get storage")
}
binding.Setup(sv)
s, err := state.New("Bot " + *globalFlags.token)
if err != nil {
return errors.Wrap(err, "Failed to get new bot state")
}
s.AddIntents(gateway.IntentDirectMessages)
s.AddIntents(gateway.IntentGuildMessages)
s.AddIntents(gateway.IntentGuildMessageReactions)
pendingEmbeds = make(chan *pendingEmbed, 512)
redirectorClosed := redirectorLoop(s, sessionSelfCloser)
err = assureCommands(s)
if err != nil {
logger.Logger.Fatalf("[MAIN] %v", err)
}
addEventHandlers(s)
addInteractionHandlers(s)
s.ErrorLog = func(innerErr error) {
logger.Logger.Errorf("[MAIN] Gateway error: %v", innerErr)
err = innerErr
select {
case <-sessionSelfCloser:
default:
close(sessionSelfCloser)
}
}
s.FatalErrorCallback = func(innerErr error) {
logger.Logger.Errorf("[MAIN] Fatal gateway error: %v", err)
err = innerErr
select {
case <-sessionSelfCloser:
default:
close(sessionSelfCloser)
}
}
s.AfterClose = func(innerErr error) {
logger.Logger.Errorf("[MAIN] After gateway closed: %v", err)
err = innerErr
select {
case <-sessionSelfCloser:
default:
close(sessionSelfCloser)
}
}
if err := s.Open(context.Background()); err != nil {
logger.Logger.Errorf("[MAIN] %v", err)
select {
case <-sessionSelfCloser:
default:
close(sessionSelfCloser)
}
}
defer s.Close()
u, err := s.Me()
if err != nil {
log.Fatalln("Failed to get myself:", err)
}
logger.Logger.Infof("Session: %d", u.ID)
s.UpdateStatus(gateway.UpdateStatusData{
Since: 0,
Activities: [] discord.Activity {
{
Name: locale.ACTIVITY,
Type: discord.WatchingActivity,
},
},
Status: discord.OnlineStatus,
AFK: false,
})
logger.Logger.Infof("====== %s at your service ======", u.Username)
promptClosed := startPromptLoop(s, sessionSelfCloser)
select {
case <-sCloser:
close(sessionSelfCloser)
case <-sessionSelfCloser:
}
s.ErrorLog = nil
os.Stdin.WriteString("o")
select {
case <-promptClosed:
case <-time.NewTimer(time.Second*5).C:
}
<-redirectorClosed
err = sv.Close()
if err != nil {
return err
}
logger.Logger.Infof("[MAIN] Session is closed.")
return nil
} |
This is worthy of its own issue. I think it would be much better if you just I'll still leave this issue open and look into why it happens, but I strongly |
Well yeah, I was rushing to put together the bot for a private server, and disconnection casually happens ~10 times a day, so I didn't consider the whole connection issue is something not-awared-of; The session loop is also to handle errors in my own logic, it worked well, therefore I just kept it as-is so far. Actually I decided to skip the re-connection very soon so it could be that I misunderstood it's not working, so I need to confirm the issue. But not very soon I'm afraid, once I got spare time to test re-connection out and discover something, I'll post. |
And several seconds before that:
Whenever a connection issue occurred, instead of tried to figure out how to reconnect, I made it to start a new state all over again, I'm wondering this could be the issue.
The text was updated successfully, but these errors were encountered: