From ceced391f3c7fae6d5b458c4ae102748e7a78c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Solymos?= <15968382+slymas@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:24:19 +0000 Subject: [PATCH] Allow non-context Dialers Dialers who don't implement DialContext but upgrade past https://github.com/fluffle/goirc/pull/109 (which is 2.5 years old but still) will break. This change falls back to the non-context dial method, where calls may take longer and time out, and goirc would give them a warning as well. --- client/connection.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/client/connection.go b/client/connection.go index aa9f2f5..5ac0918 100644 --- a/client/connection.go +++ b/client/connection.go @@ -413,15 +413,24 @@ func (conn *Conn) internalConnect(ctx context.Context) error { return err } contextProxyDialer, ok := proxyDialer.(proxy.ContextDialer) - if !ok { - return errors.New("Dialer for proxy does not support context") - } - conn.proxyDialer = contextProxyDialer - logging.Info("irc.Connect(): Connecting to %s.", conn.cfg.Server) - if s, err := conn.proxyDialer.DialContext(ctx, "tcp", conn.cfg.Server); err == nil { - conn.sock = s + if ok { + conn.proxyDialer = contextProxyDialer + logging.Info("irc.Connect(): Connecting to %s.", conn.cfg.Server) + if s, err := conn.proxyDialer.DialContext(ctx, "tcp", conn.cfg.Server); err == nil { + conn.sock = s + } else { + return err + } } else { - return err + logging.Warn("Dialer for proxy does not support context, please implement DialContext") + + conn.proxyDialer = proxyDialer + logging.Info("irc.Connect(): Connecting to %s.", conn.cfg.Server) + if s, err := conn.proxyDialer.Dial("tcp", conn.cfg.Server); err == nil { + conn.sock = s + } else { + return err + } } } else { logging.Info("irc.Connect(): Connecting to %s.", conn.cfg.Server)