Don't retry connecting on permanent failure
Closes: https://todo.sr.ht/~emersion/soju/164
This commit is contained in:
parent
578020e553
commit
fd9a935f3e
22
upstream.go
22
upstream.go
@ -39,10 +39,25 @@ var permanentUpstreamCaps = map[string]bool{
|
|||||||
"draft/extended-monitor": true,
|
"draft/extended-monitor": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
type registrationError string
|
type registrationError struct {
|
||||||
|
*irc.Message
|
||||||
|
}
|
||||||
|
|
||||||
func (err registrationError) Error() string {
|
func (err registrationError) Error() string {
|
||||||
return fmt.Sprintf("registration error: %v", string(err))
|
return fmt.Sprintf("registration error (%v): %v", err.Command, err.Reason())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err registrationError) Reason() string {
|
||||||
|
if len(err.Params) > 0 {
|
||||||
|
return err.Params[len(err.Params)-1]
|
||||||
|
}
|
||||||
|
return err.Command
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err registrationError) Temporary() bool {
|
||||||
|
// Only return false if we're 100% sure that fixing the error requires a
|
||||||
|
// network configuration change
|
||||||
|
return err.Command != irc.ERR_PASSWDMISMATCH && err.Command != irc.ERR_ERRONEUSNICKNAME
|
||||||
}
|
}
|
||||||
|
|
||||||
type upstreamChannel struct {
|
type upstreamChannel struct {
|
||||||
@ -1651,8 +1666,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
|
|||||||
return fmt.Errorf("fatal server error: %v", text)
|
return fmt.Errorf("fatal server error: %v", text)
|
||||||
case irc.ERR_PASSWDMISMATCH, irc.ERR_ERRONEUSNICKNAME, irc.ERR_NICKNAMEINUSE, irc.ERR_NICKCOLLISION, irc.ERR_UNAVAILRESOURCE, irc.ERR_NOPERMFORHOST, irc.ERR_YOUREBANNEDCREEP:
|
case irc.ERR_PASSWDMISMATCH, irc.ERR_ERRONEUSNICKNAME, irc.ERR_NICKNAMEINUSE, irc.ERR_NICKCOLLISION, irc.ERR_UNAVAILRESOURCE, irc.ERR_NOPERMFORHOST, irc.ERR_YOUREBANNEDCREEP:
|
||||||
if !uc.registered {
|
if !uc.registered {
|
||||||
text := msg.Params[len(msg.Params)-1]
|
return registrationError{msg}
|
||||||
return registrationError(text)
|
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
|
7
user.go
7
user.go
@ -221,14 +221,19 @@ func (net *network) run() {
|
|||||||
uc.register()
|
uc.register()
|
||||||
if err := uc.runUntilRegistered(); err != nil {
|
if err := uc.runUntilRegistered(); err != nil {
|
||||||
text := err.Error()
|
text := err.Error()
|
||||||
|
temp := true
|
||||||
if regErr, ok := err.(registrationError); ok {
|
if regErr, ok := err.(registrationError); ok {
|
||||||
text = string(regErr)
|
text = regErr.Reason()
|
||||||
|
temp = regErr.Temporary()
|
||||||
}
|
}
|
||||||
uc.logger.Printf("failed to register: %v", text)
|
uc.logger.Printf("failed to register: %v", text)
|
||||||
net.user.events <- eventUpstreamConnectionError{net, fmt.Errorf("failed to register: %v", text)}
|
net.user.events <- eventUpstreamConnectionError{net, fmt.Errorf("failed to register: %v", text)}
|
||||||
uc.Close()
|
uc.Close()
|
||||||
net.user.srv.metrics.upstreams.Add(-1)
|
net.user.srv.metrics.upstreams.Add(-1)
|
||||||
net.user.srv.metrics.upstreamConnectErrorsTotal.Inc()
|
net.user.srv.metrics.upstreamConnectErrorsTotal.Inc()
|
||||||
|
if !temp {
|
||||||
|
return
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user