WebThingsIO / thing-url-adapter

Proxy adapter for Web Thing API endpoints
Mozilla Public License 2.0
22 stars 18 forks source link

mDNS is unreliable #34

Closed twobraids closed 6 years ago

twobraids commented 6 years ago

I'm finding that mDNS is very unreliable, now fewer than 1 out of 10 times will the Things Gateway find my things via mDNS. I usually have to resort to typing in the URL myself, this usually works. However, if the thing being added via URL has more than one thing in it, the result is always a fail with a "invalid thing description" error. The example in the images below is an attempt to pair the webthing-python/examples/multiple-things.py example. mdns-fail mdns-fail2 mdns-fail3

mrstegeman commented 6 years ago

@twobraids We intentionally didn't support adding servers with multiple things manually, as the UI would get pretty goofy.

Is it possible your LAN isn't behaving well with mDNS? I've never personally seen this issue, so debugging will be... difficult.

mrstegeman commented 6 years ago

That said, you can add the things from the multiple-things example by addressing them individually, i.e. http:///0 and http:///1

twobraids commented 6 years ago

I can understand that debugging will be difficult for mDNS. I've got no other problems on my network with mDNS services - the Apple devices find and communicate with the Linux machines and vice versa without any appreciable trouble.

As for the multi-device server problem, we need to make the error message more useful and then document how to add the devices piecemeal.

mrstegeman commented 6 years ago

@twobraids Can you post a log somewhere that has a failed mDNS discovery? I'd like to see if there are any relevant errors.

twobraids commented 6 years ago

after about a billion reboots, I've narrowed down the behavior to this:

If the Python-Thing (single-thing.py) software is started (on Linux workstation) when the Things Gateway (on RPi) is already running, then the mDNS based discovery will fail 90% of the time. See the annotated log attached below for a connection refused error. To test if this is a timing issue, in some runs, I waited up to 30 minutes after starting the Python-Thing, before attempting to add it to the Gateway. In all cases, the program avahi-browse (run anywhere on my network) was able to see the Python-Thing immediately.

If the Python-Thing (single-thing.py) is already running when the Things Gateway is started OR if the Things Gateway is rebooted after the Python-Thing is started, then the mDNS discovery will succeed 90% of the time.

Annotated Failure run-app.log: annotated-failed-run-app.log

Successful run-app.log: success-run-app.log

mrstegeman commented 6 years ago

I see the same thing on my Mac, but I know mine is because OS X is waiting for me to approve of Python listening on a port before it will actually start listening. We need to do one (or both) of the following:

  1. Delay a bit before starting the mDNS broadcast in the webthing-X libraries.
  2. Handle this error gracefully in thing-url-adapter and retry the connection a couple of times.