MCPcopy Index your code
hub / github.com/nodejs/node / rr

Function rr

lib/internal/cluster/child.js:162–225  ·  view source on GitHub ↗
(message, { indexesKey, index }, cb)

Source from the content-addressed store, hash-verified

160
161// Round-robin. Master distributes handles across workers.
162function rr(message, { indexesKey, index }, cb) {
163 if (message.errno)
164 return cb(message.errno, null);
165
166 let key = message.key;
167
168 let fakeHandle = null;
169
170 function ref() {
171 fakeHandle ||= setInterval(noop, TIMEOUT_MAX);
172 }
173
174 function unref() {
175 if (fakeHandle) {
176 clearInterval(fakeHandle);
177 fakeHandle = null;
178 }
179 }
180
181 function listen(backlog) {
182 // TODO(bnoordhuis) Send a message to the primary that tells it to
183 // update the backlog size. The actual backlog should probably be
184 // the largest requested size by any worker.
185 return 0;
186 }
187
188 function close() {
189 // lib/net.js treats server._handle.close() as effectively synchronous.
190 // That means there is a time window between the call to close() and
191 // the ack by the primary process in which we can still receive handles.
192 // onconnection() below handles that by sending those handles back to
193 // the primary.
194 if (key === undefined)
195 return;
196 unref();
197 // If the handle is the last handle in process,
198 // the parent process will delete the handle when worker process exits.
199 // So it is ok if the close message get lost.
200 // See the comments of https://github.com/nodejs/node/pull/46161
201 send({ act: 'close', key });
202 handles.delete(key);
203 removeIndexesKey(indexesKey, index);
204 key = undefined;
205 }
206
207 function getsockname(out) {
208 if (key)
209 ObjectAssign(out, message.sockname);
210
211 return 0;
212 }
213
214 // Faux handle. net.Server is not associated with handle,
215 // so we control its state(ref or unref) by setInterval.
216 const handle = { close, listen, ref, unref };
217 handle.ref();
218 if (message.sockname) {
219 handle.getsockname = getsockname; // TCP handles only.

Callers 1

child.jsFile · 0.70

Calls 5

refMethod · 0.65
hasMethod · 0.65
cbFunction · 0.50
assertFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected