Changeset 736 in code for trunk


Ignore:
Timestamp:
Dec 2, 2021, 4:33:11 PM (4 years ago)
Author:
contact
Message:

Don't retry connecting on permanent failure

Closes: https://todo.sr.ht/~emersion/soju/164

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/upstream.go

    r732 r736  
    4040}
    4141
    42 type registrationError string
     42type registrationError struct {
     43        *irc.Message
     44}
    4345
    4446func (err registrationError) Error() string {
    45         return fmt.Sprintf("registration error: %v", string(err))
     47        return fmt.Sprintf("registration error (%v): %v", err.Command, err.Reason())
     48}
     49
     50func (err registrationError) Reason() string {
     51        if len(err.Params) > 0 {
     52                return err.Params[len(err.Params)-1]
     53        }
     54        return err.Command
     55}
     56
     57func (err registrationError) Temporary() bool {
     58        // Only return false if we're 100% sure that fixing the error requires a
     59        // network configuration change
     60        return err.Command != irc.ERR_PASSWDMISMATCH && err.Command != irc.ERR_ERRONEUSNICKNAME
    4661}
    4762
     
    16521667        case irc.ERR_PASSWDMISMATCH, irc.ERR_ERRONEUSNICKNAME, irc.ERR_NICKNAMEINUSE, irc.ERR_NICKCOLLISION, irc.ERR_UNAVAILRESOURCE, irc.ERR_NOPERMFORHOST, irc.ERR_YOUREBANNEDCREEP:
    16531668                if !uc.registered {
    1654                         text := msg.Params[len(msg.Params)-1]
    1655                         return registrationError(text)
     1669                        return registrationError{msg}
    16561670                }
    16571671                fallthrough
  • trunk/user.go

    r735 r736  
    222222                if err := uc.runUntilRegistered(); err != nil {
    223223                        text := err.Error()
     224                        temp := true
    224225                        if regErr, ok := err.(registrationError); ok {
    225                                 text = string(regErr)
     226                                text = regErr.Reason()
     227                                temp = regErr.Temporary()
    226228                        }
    227229                        uc.logger.Printf("failed to register: %v", text)
     
    230232                        net.user.srv.metrics.upstreams.Add(-1)
    231233                        net.user.srv.metrics.upstreamConnectErrorsTotal.Inc()
     234                        if !temp {
     235                                return
     236                        }
    232237                        continue
    233238                }
Note: See TracChangeset for help on using the changeset viewer.