Skip to content

Commit 83b776c

Browse files
jasnelltargos
authored andcommitted
doc: document that addMembership must be called once in a cluster
Fixes: #12572 Refs: #16240 PR-URL: #23746 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 22cd537 commit 83b776c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

doc/api/dgram.md

+18
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 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)