Cancel pending commands on downstream disconnect

If a client queues a high number of commands and then disconnects,
remove all of the pending commands. This avoids unnecessarily
sending commands whose results won't be used.
This commit is contained in:
Simon Ser 2021-12-02 19:29:44 +01:00
parent 1620344f0a
commit a413681253
2 changed files with 13 additions and 0 deletions

View File

@ -385,6 +385,18 @@ func (uc *upstreamConn) dequeueCommand(cmd string) (*downstreamConn, *irc.Messag
return dc, msg
}
func (uc *upstreamConn) cancelPendingCommandsByDownstreamID(downstreamID uint64) {
for cmd := range uc.pendingCmds {
// We can't cancel the currently running command stored in
// uc.pendingCmds[cmd][0]
for i := len(uc.pendingCmds[cmd]) - 1; i >= 1; i-- {
if uc.pendingCmds[cmd][i].downstreamID == downstreamID {
uc.pendingCmds[cmd] = append(uc.pendingCmds[cmd][:i], uc.pendingCmds[cmd][i+1:]...)
}
}
}
}
func (uc *upstreamConn) parseMembershipPrefix(s string) (ms *memberships, nick string) {
memberships := make(memberships, 0, 4)
i := 0

View File

@ -662,6 +662,7 @@ func (u *user) run() {
})
u.forEachUpstream(func(uc *upstreamConn) {
uc.cancelPendingCommandsByDownstreamID(dc.id)
uc.updateAway()
uc.updateMonitor()
})