** Summary changed:

- Python 3 variable scoping issue is hiding error tracebacks
+ [SRU] Python 3 variable scoping issue is hiding error tracebacks

** Description changed:

+ [ Impact ]
+ * In case of errors, users of deprecated amqplib Python library gets an 
useless stack trace
+ Look e.g. Britney logs when issue occurs
+ 
https://ubuntu-archive-team.ubuntu.com/proposed-migration/log/stonking/2026-06-19/07:32:15.log.gz
+ 
+ I: [2026-06-19T07:43:55+0000] - Read previous results from 
data/stonking/state/autopkgtest-results.cache
+ Traceback (most recent call last):
+   File "/home/ubuntu-archive/proposed-migration/code/b2/britney.py", line 
1629, in <module>
+     Britney().main()
+   File "/home/ubuntu-archive/proposed-migration/code/b2/britney.py", line 
401, in __init__
+     self._policy_engine.initialise(self, self.hints)
+   File 
"/home/ubuntu-archive/proposed-migration/code/b2/britney2/policies/policy.py", 
line 35, in initialise
+     policy.initialise(britney)
+   File 
"/home/ubuntu-archive/proposed-migration/code/b2/britney2/policies/autopkgtest.py",
 line 313, in initialise
+     self.amqp_con = amqp.Connection(creds.hostname, userid=creds.username,
+   File "/usr/lib/python3/dist-packages/amqplib/client_0_8/connection.py", 
line 129, in __init__
+     self.transport = create_transport(host, connect_timeout, ssl)
+   File "/usr/lib/python3/dist-packages/amqplib/client_0_8/transport.py", line 
281, in create_transport
+     return TCPTransport(host, connect_timeout)
+   File "/usr/lib/python3/dist-packages/amqplib/client_0_8/transport.py", line 
85, in __init__
+     raise socket.error(msg)
+ UnboundLocalError: local variable 'msg' referenced before assignment
+ 
+ 
+ This stack trace doesn't help understanding there was a network failure
+ 
+ [ Test Plan ]
+ * Install the library, disable network, get a stacktrace
+ 
+ [ Where problem could occur ]
+ * This is an useful fix for Britney in case of network issues
+ 
+ [ Other Info ]
+ 
  A script my team uses python3-amqplib for RabbitMQ connectivity
  checking, but in the case of not being able to connect, the error we get
  when running from Python 3 hides the real problem behind a Python 3
  variable scoping issue.
  
  This is reproducible via: python3 -c "from amqplib import client_0_8 as
  amqp; amqp.Connection()"
  
  The above will generate this output (assuming no RabbitMQ is running on
  your system):
  
  Traceback (most recent call last):
-   File "<string>", line 1, in <module>
-   File "/usr/lib/python3/dist-packages/amqplib/client_0_8/connection.py", 
line 129, in __init__
-     self.transport = create_transport(host, connect_timeout, ssl)
-   File "/usr/lib/python3/dist-packages/amqplib/client_0_8/transport.py", line 
281, in create_transport
-     return TCPTransport(host, connect_timeout)
-   File "/usr/lib/python3/dist-packages/amqplib/client_0_8/transport.py", line 
85, in __init__
-     raise socket.error(msg)
+   File "<string>", line 1, in <module>
+   File "/usr/lib/python3/dist-packages/amqplib/client_0_8/connection.py", 
line 129, in __init__
+     self.transport = create_transport(host, connect_timeout, ssl)
+   File "/usr/lib/python3/dist-packages/amqplib/client_0_8/transport.py", line 
281, in create_transport
+     return TCPTransport(host, connect_timeout)
+   File "/usr/lib/python3/dist-packages/amqplib/client_0_8/transport.py", line 
85, in __init__
+     raise socket.error(msg)
  UnboundLocalError: local variable 'msg' referenced before assignment
  
  I would instead expect the following, which I see on Bionic when running
  the same command from above, but via Python 2 instead:
  
  Traceback (most recent call last):
-   File "<string>", line 1, in <module>
-   File "/usr/lib/python2.7/dist-packages/amqplib/client_0_8/connection.py", 
line 129, in __init__
-     self.transport = create_transport(host, connect_timeout, ssl)
-   File "/usr/lib/python2.7/dist-packages/amqplib/client_0_8/transport.py", 
line 281, in create_transport
-     return TCPTransport(host, connect_timeout)
-   File "/usr/lib/python2.7/dist-packages/amqplib/client_0_8/transport.py", 
line 85, in __init__
-     raise socket.error, msg
+   File "<string>", line 1, in <module>
+   File "/usr/lib/python2.7/dist-packages/amqplib/client_0_8/connection.py", 
line 129, in __init__
+     self.transport = create_transport(host, connect_timeout, ssl)
+   File "/usr/lib/python2.7/dist-packages/amqplib/client_0_8/transport.py", 
line 281, in create_transport
+     return TCPTransport(host, connect_timeout)
+   File "/usr/lib/python2.7/dist-packages/amqplib/client_0_8/transport.py", 
line 85, in __init__
+     raise socket.error, msg
  socket.error: [Errno 111] Connection refused
  
  In Python 2, we get "Connection refused" - in Python 3, we get a Python
  error, which hides the "Connection refused" message.
  
  ProblemType: Bug
  DistroRelease: Ubuntu 20.04
  Package: python3-amqplib (not installed)
  ProcVersionSignature: Ubuntu 5.4.0-47.51-generic 5.4.55
  Uname: Linux 5.4.0-47-generic x86_64
  NonfreeKernelModules: zfs zunicode zavl icp zcommon znvpair
  ApportVersion: 2.20.11-0ubuntu27.8
  Architecture: amd64
  CasperMD5CheckResult: skip
  CurrentDesktop: ubuntu:GNOME
  Date: Wed Sep 16 14:08:00 2020
  InstallationDate: Installed on 2019-01-04 (621 days ago)
  InstallationMedia: Ubuntu 18.10 "Cosmic Cuttlefish" - Release amd64 
(20181017.3)
  SourcePackage: python-amqplib
  UpgradeStatus: Upgraded to focal on 2020-01-31 (229 days ago)

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1895893

Title:
  [SRU] Python 3 variable scoping issue is hiding error tracebacks

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python-amqplib/+bug/1895893/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to