Skip to content

Commit

Permalink
fix(plc4go/opcua): fixed issue regarding host revolving
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 7, 2023
1 parent 2fea480 commit a8c6d26
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions plc4go/internal/opcua/SecureChannel.go
Expand Up @@ -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)
Expand Down

0 comments on commit a8c6d26

Please sign in to comment.