Skip to content

BUG: socket.bind('tcp://127.0.0.1:...') fails with ZMQError: Invalid argument on macOS ARM with pyzmq 26.4.0 #2093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
itsmevictor opened this issue Apr 21, 2025 · 6 comments

Comments

@itsmevictor
Copy link

itsmevictor commented Apr 21, 2025

This is a pyzmq bug

  • This is a pyzmq-specific bug, not an issue of zmq socket behavior. Don't worry if you're not sure! We'll figure it out together.

What pyzmq version?

26.4.0

What libzmq version?

4.3.5_1 (Installed separately via Homebrew)

Python version (and how it was installed)

Python 3.11.12 (Installed via Homebrew)

OS

macOS Sequoia

What happened?

Summary:

When using pyzmq version 26.4.0 on macOS ARM with Python 3.11 (installed via Homebrew) and libzmq 4.3.5_1 (also installed via Homebrew), attempting to bind a socket to a localhost TCP address fails with zmq.error.ZMQError: Invalid argument.

Expected behavior:
The socket.bind('tcp://127.0.0.1:<port>') call should succeed without raising an exception.

Actual behavior:
The call raises the following exception: zmq.error.ZMQError: Invalid argument (addr='tcp://127.0.0.1:<port>')

Code to reproduce bug

import zmq
import platform

print(f"pyzmq version: {zmq.pyzmq_version()}")
print(f"libzmq version: {zmq.zmq_version()}")
print(f"Python version: {platform.python_version()}")
print(f"OS: {platform.system()} {platform.release()} ({platform.machine()})")

ctx = zmq.Context()
sock = ctx.socket(zmq.REP)
address = 'tcp://127.0.0.1:9027' # Example port

try:
    print(f"Attempting to bind to {address}...")
    sock.bind(address) 
    print("Bind successful!")
    sock.close()
except zmq.error.ZMQError as e:
    print(f"Bind failed: {e}") # This is where the error occurs
except Exception as e:
    print(f"An unexpected error occurred: {e}")
finally:
    if not sock.closed:
        sock.close()
    ctx.term()

Finally, reverting to 25.1.2 solved the issue.

@dhagrow
Copy link

dhagrow commented Apr 21, 2025

I am seeing the same error with both bind and connect on Windows 10 Enterprise LTSC 2019:

Traceback (most recent call last):
  ...
_zmq.py:968: in zmq.backend.cython._zmq.Socket.connect
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>   ???
E   zmq.error.ZMQError: Invalid argument (addr='tcp://127.0.0.1:4568')
_zmq.py:180: ZMQError
Traceback (most recent call last):
  ...
  File "_zmq.py", line 942, in zmq.backend.cython._zmq.Socket.bind
  File "_zmq.py", line 180, in zmq.backend.cython._zmq._check_rc
zmq.error.ZMQError: Invalid argument (addr='tcp://127.0.0.1:4567')

I don't see the error on other versions of Windows.

@minrk
Copy link
Member

minrk commented Apr 21, 2025

This is my output from @itsmevictor's script (also arm mac, homebrew Python 3.11):

> brew install [email protected]
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.11/manifests/3.11.12
############################################################################################################################################################################################################### 100.0%
==> Fetching [email protected]
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.11/blobs/sha256:ef44fa3fc4d611b9d18af77e61fec677986cafc96a92ff733ad971178b1afbc2
############################################################################################################################################################################################################### 100.0%
==> Verifying attestation for [email protected]
==> Pouring [email protected]_sequoia.bottle.tar.gz
==> /opt/homebrew/Cellar/[email protected]/3.11.12/bin/python3.11 -Im ensurepip
==> /opt/homebrew/Cellar/[email protected]/3.11.12/bin/python3.11 -Im pip install -v --no-index --upgrade --isolated --target=/opt/homebrew/lib/python3.11/site-packages /opt/homebrew/Cellar/[email protected]/3.11.12/Frameworks
==> Caveats
Python is installed as
  /opt/homebrew/bin/python3.11
...
> /opt/homebrew/bin/python3.11 -m venv ./venv
> source ./venv/bin/activate
> pip install pyzmq
Collecting pyzmq
  Downloading pyzmq-26.4.0-cp311-cp311-macosx_10_15_universal2.whl.metadata (6.0 kB)
Downloading pyzmq-26.4.0-cp311-cp311-macosx_10_15_universal2.whl (1.3 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 36.1 MB/s eta 0:00:00
Installing collected packages: pyzmq
Successfully installed pyzmq-26.4.0
(venv) minrk@heavy-7 [19:37:38] ~/dev/temp
> python3 test.py
pyzmq version: 26.4.0
libzmq version: 4.3.5
Python version: 3.11.12
OS: Darwin 24.4.0 (arm64)
Attempting to bind to tcp://127.0.0.1:9027...
Bind successful!

Did you get pyzmq from a wheel or compile from source?

Do other local addresses work, e.g.

  • "tcp://*:9027"
  • "tcp://0.0.0.0:9027"
  • "tcp://localhost:9027"

Does any 26.x work, or only 25.x?

Here's a script that lets you try more things at once:

import platform
import time

import zmq

print(f"pyzmq version: {zmq.pyzmq_version()}")
print(f"libzmq version: {zmq.zmq_version()}")
print(f"Python version: {platform.python_version()}")
print(f"OS: {platform.system()} {platform.release()} ({platform.machine()})")

with zmq.Context() as ctx:
    for address in [
        'tcp://localhost:9027',
        'tcp://127.0.0.1:9027',
        'tcp://0.0.0.0:9027',
        'tcp://*:9027',
        'tcp://127.0.0.1:65500',
    ]:
        with ctx.socket(zmq.REP) as sock:
            time.sleep(0.2)
            try:
                print(f"Attempting to bind to {address}...")
                sock.bind(address) 
                print("Bind successful!")
            except zmq.error.ZMQError as e:
                print(f"Bind failed: {e}") # This is where the error occurs
            except Exception as e:
                print(f"An unexpected error occurred: {e}")

@itsmevictor
Copy link
Author

itsmevictor commented Apr 21, 2025

Thanks for your quick response @minrk. I'm not going to be able to perform further testing (i.e. uninstalling 25.x, installing 26.x) right now, but to answer your questions in the meantime:

  1. I got pyzmq from wheel, with pip install.
  2. I tried several local addresses and none worked.

I'll try to conduct further testing tomorrow.

@NikolaiUgelvik
Copy link

NikolaiUgelvik commented May 10, 2025

Seeing the same thing on windows, but only when running in the vscode debugger for some reason.

Edit: Downgrading to 26.3.0 worked.

@autra
Copy link

autra commented May 21, 2025

Seeing similar error on linux with ipc socket:

Traceback (most recent call last):
  File "/home/augustin/workspace/py3dtiles/.venv3.9.21/bin/py3dtiles", line 8, in <module>
    sys.exit(main())
  File "/home/augustin/workspace/py3dtiles/py3dtiles/command_line.py", line 27, in main
    convert._main(args)
  File "/home/augustin/workspace/py3dtiles/py3dtiles/convert.py", line 567, in _main
    return convert(
  File "/home/augustin/workspace/py3dtiles/py3dtiles/convert.py", line 273, in convert
    converter = _Convert(
  File "/home/augustin/workspace/py3dtiles/py3dtiles/convert.py", line 381, in __init__
    self.zmq_manager = _ZmqManager(
  File "/home/augustin/workspace/py3dtiles/py3dtiles/convert.py", line 156, in __init__
    self.socket.bind(URI)
  File "/home/augustin/workspace/py3dtiles/.venv3.9.21/lib/python3.9/site-packages/zmq/sugar/socket.py", line 320, in bind
    super().bind(addr)
  File "_zmq.py", line 942, in zmq.backend.cython._zmq.Socket.bind
  File "_zmq.py", line 180, in zmq.backend.cython._zmq._check_rc
zmq.error.ZMQError: Invalid argument (addr='ipc:///tmp/tmpk23hrjtt/py3dtiles.sock')

It disappears when downgrading to 26.3.0.

Context: https://gitlab.com/py3dtiles/py3dtiles/

@filip-halt
Copy link

Im also having this issue on an M1 Max running Sequoia 15.5. Downgrading to 26.3 has fixed it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants