-
Notifications
You must be signed in to change notification settings - Fork 669
Description
Hello,
I use python-opcua (0.98.3) to create a client which subscribes to datachanges on several nodes. (Thank you to every contributor for the work you put in this package by the way, it proves very useful !)
More often than not, after 7 or 8 minutes a problem occures where a signature fails to be validated and the library raise an InvalidSignature error.
I don't know if the signature error in itself comes from python-opcua or from the server (but it is not simply random so if someone else faces this problem you may consider creating a dedicated issue).
The main problem in my opinion is that this InvalidSignature exception is never caught by the library and since it is in a child thread, it's very hard to catch for the user. As a result, the child thread crashes, soon after that a second crash occures (TimeoutError) (not caught either), and the main thread is never notified that the connexion is no longer working.
Here are the two exceptions I receive:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/user/.local/lib/python2.7/site-packages/opcua/client/ua_client.py", line 95, in _run
self._receive()
File "/home/user/.local/lib/python2.7/site-packages/opcua/client/ua_client.py", line 104, in _receive
msg = self._connection.receive_from_socket(self._socket)
File "/home/user/.local/lib/python2.7/site-packages/opcua/common/connection.py", line 309, in receive_from_socket
return self.receive_from_header_and_body(header, ua.utils.Buffer(body))
File "/home/user/.local/lib/python2.7/site-packages/opcua/common/connection.py", line 280, in receive_from_header_and_body
header, body)
File "/home/user/.local/lib/python2.7/site-packages/opcua/common/connection.py", line 55, in from_header_and_body
crypto.verify(header_to_binary(obj.MessageHeader) + struct_to_binary(obj.SecurityHeader) + decrypted, signature)
File "/home/user/.local/lib/python2.7/site-packages/opcua/crypto/security_policies.py", line 155, in verify
self.Verifier.verify(data, sig)
File "/home/user/.local/lib/python2.7/site-packages/opcua/crypto/security_policies.py", line 276, in verify
raise uacrypto.InvalidSignature
InvalidSignature
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/home/user/.local/lib/python2.7/site-packages/opcua/client/client.py", line 62, in run
val = server_state.get_value()
File "/home/user/.local/lib/python2.7/site-packages/opcua/common/node.py", line 148, in get_value
result = self.get_data_value()
File "/home/user/.local/lib/python2.7/site-packages/opcua/common/node.py", line 157, in get_data_value
return self.get_attribute(ua.AttributeIds.Value)
File "/home/user/.local/lib/python2.7/site-packages/opcua/common/node.py", line 266, in get_attribute
result = self.server.read(params)
File "/home/user/.local/lib/python2.7/site-packages/opcua/client/ua_client.py", line 304, in read
data = self._uasocket.send_request(request)
File "/home/user/.local/lib/python2.7/site-packages/opcua/client/ua_client.py", line 77, in send_request
data = future.result(self.timeout)
File "/home/user/.local/lib/python2.7/site-packages/concurrent/futures/_base.py", line 464, in result
raise TimeoutError()
TimeoutError
I managed to create a workaround where I catch exceptions from every thread in my software. But I think the library should definitely catch these exceptions (and really any exception raised in secondary threads) and offer some way for the user to detect that something wrong occured (maybe something as simple as a threading.Event).