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
Support quit messages through type Config, c.Cmd.Quit(), or a c.Close() wrapper #16
Comments
You could always send a raw message to handle this. I don't necessarily like the |
I've been playing around with it, and since there is no |
If the client sends a Will poke it more when I get a chance. |
Actually, scratch the "making disconnected := make(chan struct{})
c.Handlers.Add(girc.STOPPED, func(c *girc.Client, e girc.Event) {
log.Printf("DISCONNECTED")
disconnected <- struct{}{}
}) c.Handlers.Add(girc.PRIVMSG, func(c *girc.Client, e girc.Event) {
if strings.HasPrefix(e.Trailing, "!stop") {
//c.Cmd.SendRaw("QUIT :Received command '!stop'")
c.Close() // triggers girc.STOPPED
}
}) done := false
go func() {
for {
if err = c.Connect(); err != nil && !done {
log.Printf("Error connecting to %s (%d): %v",
cfg.Hostname, cfg.Port, err)
log.Print("Reconnecting in 15 seconds...")
time.Sleep(15 * time.Second)
} else {
return
}
}
}()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)
for {
select {
case sig := <-sigs:
switch sig {
case syscall.SIGUSR1:
continue
case syscall.SIGINT, syscall.SIGTERM:
done = true
log.Printf("Received signal '%s' to shut down", sig)
if c.IsConnected() {
// c.Cmd.SendRawf("QUIT :Received signal '%s' to shut down", sig)
// time.Sleep(5 * time.Second) // ↑ would work with this workaround
c.Close() // doesn't trigger girc.STOPPED
}
return
}
case <-disconnected:
log.Printf("DISCONNECTED #2")
return
}
} So the issues are:
Additionally, omitting
The reason I am calling Hmm, apparently trying this: if c.IsConnected() {
c.Cmd.SendRawf("QUIT :Received signal '%s' to shut down", sig)
c.Close()
time.Sleep(2 * time.Second)
}
return does print "DISCONNECTED" and quits with "Connection closed", but it depends on an arbitrary number of seconds, and it's of course non-deterministic, and a terrible workaround. I did try eliminating This seems to do the job perfectly with no arbitrary seconds of sleeping with for c.IsConnected() {
c.Cmd.SendRawf("QUIT :Received signal '%s' to shut down", sig)
}
return Apparently this particular code works in this instance, too: c.Handlers.Add(girc.PRIVMSG, func(c *girc.Client, e girc.Event) {
if strings.HasPrefix(e.Trailing, "!stop") {
for c.IsConnected() {
c.Cmd.SendRawf("QUIT :Foobar")
}
}
}) I get:
Aaaand it does reconnect and works as expected! I am not sure what to make of the two errors right now, but I guess I could workaround them. TL;DR: After having spent a few minutes on this, my issue has been resolved and both quitting with a specified error message (in two different instances), and auto-reconnect works. What's left for you to do is perhaps add For completeness' sake: done := false
go func() {
for {
if err = c.Connect(); err != nil && !done {
log.Printf("Error connecting to %s (%d): %v",
cfg.Hostname, cfg.Port, err)
log.Print("Reconnecting in 15 seconds...")
time.Sleep(15 * time.Second)
} else {
return
}
}
}()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1)
for sig := range sigs {
switch sig {
case syscall.SIGUSR1:
continue
case syscall.SIGINT, syscall.SIGTERM:
done = true
log.Printf("Received signal '%s' to shut down", sig)
for c.IsConnected() {
c.Cmd.SendRawf("QUIT :Received signal '%s' to shut down", sig)
}
return
}
} |
Utilizing The ideal solution is something like |
You are right about the unnecessary, and potential flooding. Sending |
To ensure that new listeners / files aren't created after / during the cleanup (e.g. through RPL_MONONLINE messages). Discussion: Sending a QUIT command and blocking until the client quit would be preferable, unfortunately such a command is not available. See: lrstanley/girc#16
To ensure that new listeners / files aren't created after / during the cleanup (e.g. through RPL_MONONLINE messages). Discussion: Sending a QUIT command and blocking until the client quit would be preferable, unfortunately such a command is not available. See: lrstanley/girc#16
To ensure that new listeners / files aren't created after / during the cleanup (e.g. through RPL_MONONLINE messages). Discussion: Sending a QUIT command and blocking until the client quit would be preferable, unfortunately such a function is not available. See: lrstanley/girc#16
To ensure that new listeners / files aren't created after / during the cleanup (e.g. through RPL_MONONLINE messages). Discussion: Sending a QUIT command and blocking until the client quit would be preferable, unfortunately such a function is not available. See: lrstanley/girc#16
Sorry for the delay in taking a better look at this. This should be resolved with 05b8be7; let me know if you have any issues. |
Great news, thanks a lot! One thing I noticed though is that the QUIT event doesn't seem to get propagated to a The messages does show up in the debug log though. UPDATE: Never mind, forgot that this is a TX event (which is why it doesn't show up in a |
How about we add a struct field
QuitMessage
totype Config
and use this quit message upon graceful exit?Are there any ways to do this currently, as in quit with a specified quit message whenever (for example when handling signals)?
The text was updated successfully, but these errors were encountered: