From f5b16dc00c7b2620a4e664ded60b524c56f29b79 Mon Sep 17 00:00:00 2001 From: delthas Date: Sun, 20 Mar 2022 14:51:34 +0100 Subject: [PATCH] Send any welcome error messages to the downstream Currently, if we fail connecting to a new networking during welcome, we send no error message to the client, and the connection remains open in an undefined state. Given the input: NICK nick USER user/invalid.xyz s e r PASS pass soju will fail to connect, add a message to its own logs, but will return no message to the downstream. This fixes the issue by forwarding the error message if it is an IRC error message (which it is for connecting to new networks). We should probably also close the connection after the message is written, because it leaves the connection in an undefined state. This is TODO for now because we'd have to wait for the error message to be written out first, which is non-trivial. --- user.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/user.go b/user.go index b90a4f2..e8a05f7 100644 --- a/user.go +++ b/user.go @@ -632,7 +632,18 @@ func (u *user) run() { } if err := dc.welcome(context.TODO()); err != nil { + if ircErr, ok := err.(ircError); ok { + msg := ircErr.Message.Copy() + msg.Prefix = dc.srv.prefix() + dc.SendMessage(msg) + } else { + dc.SendMessage(&irc.Message{ + Command: "ERROR", + Params: []string{"Internal server error"}, + }) + } dc.logger.Printf("failed to handle new registered connection: %v", err) + // TODO: close dc after the error message is sent break }