mtconnect / cppagent

C++ Agent toolkit - Pre-built binaries, visit: https://github.com/mtconnect/cppagent/releases Docker images available at https://hub.docker.com/repositories/mtconnect
http://mtcup.org/
Apache License 2.0
141 stars 91 forks source link

Agent Crash when configured for TWO adapters #472

Closed neildes2 closed 4 months ago

neildes2 commented 4 months ago

Agent v2.3.0.14

It appears that if an adapter fails to connect, it will try to connect to localhost 7878. A default. This causes an issue if there are two adapters configured and one of them fails to connect. You end up with duplicate adapter settings and the agent crashes.
I had a shdr adapter followed by an mqtt broker adapter. If the mqtt adapter fails, I ended up with TWO localhost 7878 adapters.

Adapters{ device{ Host = localhost Port = 7878 } device{ URL = mqtt://10.x.x.x:1883 . . . } }

image

Note that this only happens if the mqtt broker URL has a forward slash "/" at the end of it.

    Url = mqtt://10.1.2.3/
    MqttPort = 1885
wsobel commented 4 months ago

You can't have two adapters with the same name. Did you try changing the name of the second adapter?

Maybe this just needs better error handling.

neildes2 commented 4 months ago

I changed the names to machine1 and machine2 and still got the error...

image

neildes2 commented 4 months ago

Looks like the issue is with duplicate adapter URLs in the AGENT device adapter listings. If the mqtt adapter connects to the broker, there is no issue. Its when it doesnt connect, it defaults to localhost 7878

wsobel commented 4 months ago

I'll check this out. I have no idea how the host and port are getting reset when it doesn't connect.

Can you upload you cfg file?

neildes2 commented 4 months ago

When it cant connect, it tries to connect to localhost 7878. I think this was an AUTO repair feature of some sort. The problem is if I have a second adapter already set to localhost 7878, it generates an error and crashes.

wsobel commented 4 months ago

Can you paste the lines from there cfg for all the adapters.

neildes2 commented 4 months ago

This Crashes...

Devices = Devices.xml AgentDeviceUUID = "3519a48b-814b-3425-a12d-ef250947ab3d" PreserveUUID = true Port = 5000 BufferSize = 17 MaxAssets = 1024 SchemaVersion = 2.2 ShdrVersion = 1 SuppressIPAddress = false DisableAgentDevice = false MonitorConfigFiles = false WorkerThreads = 2 JsonVersion = 1 ConversionRequired = true IgnoreTimestamps = true Pretty = true HeartBeat = 60000

Adapters {

machine1{ Device = machine Host = localhost Port = 7878

}

machine2 { Device = machine Url = mqtt://10.1.2.3/ MqttPort = 1885 MqttUserName = user1 MqttPassword = "password" Topics = "machinename/ingress/#" MqttClientId = machinename-1333

} }

Logger Configuration

logger_config {

logging_level = trace

}

wsobel commented 4 months ago

Thanks. I'll try to reproduce

wsobel commented 4 months ago

The issue was with URL parsing and I have a fix in the current 472 branch.