crossbario / autobahn-python

WebSocket and WAMP in Python for Twisted and asyncio
https://crossbar.io/autobahn
MIT License
2.48k stars 766 forks source link

String formatting errors for log messages in protocol.py #1409

Open Shivlocin opened 4 years ago

Shivlocin commented 4 years ago

Autobahn version: 20.7.1 OS: Ubuntu 20.04 & RHEL 7 Python version: 3.8.2 & 3.6.8

Steps to reproduce:

  1. Start a crossbar router
  2. Run a basic application derived from ApplicationSession with an onJoin function.
  3. Kill crossbar router Basic application will throw exception during teardown.

Traceback (most recent call last): File "/home/ja30047/.local/lib/python3.6/site-packages/autobahn/wamp/websocket.py", line 78, in onClose self._session.onClose(wasClean) File "/home/ja30047/.local/lib/python3.6/site-packages/autobahn/wamp/protocol.py", line 1276, in onClose txaio.add_callbacks(d, success, _error) File "/home/ja30047/.local/lib/python3.6/site-packages/txaio/tx.py", line 443, in add_callbacks future.addCallbacks(callback, errback) File "/home/ja30047/.local/lib/python3.6/site-packages/twisted/internet/defer.py", line 311, in addCallbacks self._runCallbacks() --- --- File "/home/ja30047/.local/lib/python3.6/site-packages/twisted/internet/defer.py", line 654, in _runCallbacks current.result = callback(current.result, *args, **kw) File "/home/ja30047/.local/lib/python3.6/site-packages/autobahn/wamp/protocol.py", line 1275, in _error return self._swallow_error(e, "While firing onDisconnect") File "/home/ja30047/.local/lib/python3.6/site-packages/autobahn/wamp/protocol.py", line 490, in _swallow_error tb=txaio.failure_format_traceback(txaio.create_failure()), builtins.TypeError: error() got an unexpected keyword argument 'tb'

Caused by the following on line 489 of Protocol.py(Version 20.7.1) self.log.error( "Internal error: {tb}", tb=txaio.failure_format_traceback(txaio.create_failure()), ) tb is not a known argument for the log.error method thus the exception above. Propose changing to the following: self.log.error( "Internal error: {tb}".format( tb=txaio.failure_format_traceback(txaio.create_failure())), )

This eliminates the TypeError exception. Now following exception is thrown:

2020-08-07T17:35:11-0400 [Container 18175] Connection to node controller closed cleanly 2020-08-07T17:35:11-0400 [Container 18175] [ENVNotifier] (ERROR): Internal error: Traceback (most recent call last): 2020-08-07T17:35:11-0400 [Container 18175] File "/home/ja30047/.local/lib/python3.6/site-packages/txaio/tx.py", line 443, in add_callbacks 2020-08-07T17:35:11-0400 [Container 18175] future.addCallbacks(callback, errback) 2020-08-07T17:35:11-0400 [Container 18175] File "/home/ja30047/.local/lib/python3.6/site-packages/twisted/internet/defer.py", line 311, in addCallbacks 2020-08-07T17:35:11-0400 [Container 18175] self._runCallbacks() 2020-08-07T17:35:11-0400 [Container 18175] File "/home/ja30047/.local/lib/python3.6/site-packages/twisted/internet/defer.py", line 654, in _runCallbacks 2020-08-07T17:35:11-0400 [Container 18175] current.result = callback(current.result, *args, **kw) 2020-08-07T17:35:11-0400 [Container 18175] File "/home/ja30047/.local/lib/python3.6/site-packages/autobahn/wamp/protocol.py", line 1262, in _error 2020-08-07T17:35:11-0400 [Container 18175] return self._swallow_error(e, "While firing onLeave") 2020-08-07T17:35:11-0400 [Container 18175] --- --- 2020-08-07T17:35:11-0400 [Container 18175] File "/home/ja30047/.local/lib/python3.6/site-packages/autobahn/wamp/protocol.py", line 486, in _swallow_error 2020-08-07T17:35:11-0400 [Container 18175] self.onUserError(fail, msg) 2020-08-07T17:35:11-0400 [Container 18175] File "/home/ja30047/.local/lib/python3.6/site-packages/autobahn/wamp/protocol.py", line 470, in onUserError 2020-08-07T17:35:11-0400 [Container 18175] traceback=txaio.failure_format_traceback(fail), 2020-08-07T17:35:11-0400 [Container 18175] builtins.TypeError: error() got an unexpected keyword argument 'klass'

Same formatting for log messages cause exception. I'm able to make this correction and submit a PR if suggestion is approved.

oberstet commented 3 years ago

tb is not a known argument for the log.error method thus the exception above.

mmh, that method accepts arbitrary kwargs:

https://github.com/crossbario/autobahn-python/blob/3ea4fdae9814641f6dcc03a2deb4e555b2f9a776/autobahn/wamp/protocol.py#L74 https://github.com/crossbario/txaio/blob/29643c6361fb16c6a67d3921b09b860748a6a936/txaio/interfaces.py#L138