You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/08/07 12:40:57 UTC

[plc4x] 03/08: fix(plc4go/opcua): fixed issue regarding host revolving

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit a8c6d26e9b3f2b036456b12b5d3b718bd237e00e
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Aug 7 11:59:42 2023 +0200

    fix(plc4go/opcua): fixed issue regarding host revolving
---
 plc4go/internal/opcua/SecureChannel.go | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/plc4go/internal/opcua/SecureChannel.go b/plc4go/internal/opcua/SecureChannel.go
index 2eb817daea..cdb1a1c58d 100644
--- a/plc4go/internal/opcua/SecureChannel.go
+++ b/plc4go/internal/opcua/SecureChannel.go
@@ -165,15 +165,22 @@ func NewSecureChannel(log zerolog.Logger, ctx DriverContext, configuration Confi
 	}
 
 	// Generate a list of endpoints we can use.
-	if address, err := url.Parse("none:" + configuration.host); err != nil {
-		if names, err := net.LookupAddr(address.Host); err != nil {
-			s.endpoints = append(s.endpoints, names[rand.Intn(len(names))])
+	{
+		var err error
+		address, err := url.Parse("none://" + configuration.host)
+		if err == nil {
+			if names, lookupErr := net.LookupHost(address.Host); lookupErr == nil {
+				s.endpoints = append(s.endpoints, names[rand.Intn(len(names))])
+				s.endpoints = append(s.endpoints, address.Host)
+				//s.endpoints = append(s.endpoints, address.Host)//TODO: not sure if golang can do
+			} else {
+				err = lookupErr
+			}
+		}
+		if err != nil {
+			s.log.Warn().Err(err).Msg("Unable to resolve host name. Using original host from connection string which may cause issues connecting to server")
+			s.endpoints = append(s.endpoints, address.Host)
 		}
-		s.endpoints = append(s.endpoints, address.Host)
-		//s.endpoints = append(s.endpoints, address.Host)//TODO: not sure if golang can do
-	} else {
-		s.log.Warn().Msg("Unable to resolve host name. Using original host from connection string which may cause issues connecting to server")
-		s.endpoints = append(s.endpoints, address.Host)
 	}
 
 	s.channelId.Store(1)