Open wolph opened 4 years ago
This is a bit more invovled than reusing the existing connection. I've done a small test with connection re-use, and its incredibly easy to break. In this case i've set it so the RouterOS API Client is created and 'stored' in the collector struct, re-used if it is not nil. If two requests are made to the collector at the same time (or whilst another Collect is in progress) it will cause the second request to 'hang', and no more requests will be successful to that device.
There are few ways I can think of solving this
I'm leaning towards the third option my self.
Hmm, that's harder than I had hoped. I was somehow assuming that the requests would be fast enough that a simple threading.Semaphore
would be enough to solve those issues.
Effectively:
semaphore = threading.Semaphore()
# Do something
if semaphore.acquire(timeout=10):
# Execute the code
else:
# Timeout, reconnect maybe?
It's probably something that should be implemented in the upstream Client API Library either via a long lived connection with a health checking mechanism and reconnect logic. I think even with the multiple commands call it would still get the connected/disconnected messages in the log file.
While from a security perspective not great the fix for me was excluding the account topic:
Right now the collector seems to login/logout continuously. Would it be possible to simply stay logged in so you don't get logs filled with connected/disconnected messages?