Skip to content

Commit 08c277c

Browse files
committed
doc: document that addMembership must be called once in a cluster
Fixes: nodejs#12572 Refs: nodejs#16240
1 parent 9c82a1e commit 08c277c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

doc/api/dgram.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ Tells the kernel to join a multicast group at the given `multicastAddress` and
9595
one interface and will add membership to it. To add membership to every
9696
available interface, call `addMembership` multiple times, once per interface.
9797

98+
When sharing a UDP socket across multiple `cluster` workers, the
99+
`socket.addMembership()` function must only be called *only once* or an
100+
`EADDRINUSE` error will occur:
101+
102+
```js
103+
const cluster = require('cluster');
104+
const dgram = require('dgram');
105+
if (cluster.isMaster) {
106+
cluster.fork(); // Works ok
107+
cluster.fork(); // Fails with EADDRINUSE
108+
} else {
109+
const s = dgram.createSocket('udp4');
110+
s.bind(1234, () => {
111+
s.addMembership('224.0.0.114');
112+
});
113+
}
114+
```
115+
98116
### socket.address()
99117
<!-- YAML
100118
added: v0.1.99

0 commit comments

Comments
 (0)