zeromq.js icon indicating copy to clipboard operation
zeromq.js copied to clipboard

unable to unbindSync from a publisher socket with compat mode

Open Wayonb opened this issue 10 months ago • 1 comments

Describe the bug I might be doing something incorrect here, but when I call unbindSync it gives the error Error: Address already in use.

Reproducing

* eslint-disable */
import zmq from 'zeromq/v5-compat.js';

function main() {
	const pub = zmq.socket("pub")
	const sub = zmq.socket("sub")

	pub.on("bind", address => {
		console.log(`Bound to ${address}`)
	})

	pub.bind("tcp://127.0.0.1:3456", err => {
		if (err) {
			throw err
		}

		sub.connect("tcp://127.0.0.1:3456")
		console.log("Subscriber connected to tcp://127.0.0.1:3456")

		sub.on("message", msg => {
			// Handle received message...
			console.log(`Received message: ${msg.toString()}`)
		})

		pub.send("message")
	})

	setTimeout(() => {
		pub.unbindSync("tcp://127.0.0.1:3456")
		process.exit(0)
	}, 2000)
}

main()
Bound to tcp://127.0.0.1:3456
Subscriber connected to tcp://127.0.0.1:3456
node_modules/zeromq/lib/compat.js:291
        this._socket.unbindSync(address);
                     ^

Error: Address already in use
    at Socket.unbindSync (node_modules/zeromq/lib/compat.js:291:22)
    at Timeout._onTimeout (file:///zeromq.js:30:7)
    at listOnTimeout (node:internal/timers:581:17)
    at process.processTimers (node:internal/timers:519:7) {
  errno: 98,
  code: 'EADDRINUSE',
  address: 'tcp://127.0.0.1:3456'
}

Node.js v20.18.3

Expected behavior Since the address is already in use, I expected unbindSync to release the port

Tested on

  • OS: Ubuntu 24.04
  • Node.js 20
  • ZeroMQ.js version: 6.3.0

Wayonb avatar Feb 20 '25 04:02 Wayonb

Can you try using await unbind? The unbindSync implementation was added recently, and there might be some corner cases.

aminya avatar Mar 04 '25 08:03 aminya