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

Function queryServer

lib/internal/cluster/primary.js:268–330  ·  view source on GitHub ↗
(worker, message)

Source from the content-addressed store, hash-verified

266}
267
268function queryServer(worker, message) {
269 // Stop processing if worker already disconnecting
270 if (worker.exitedAfterDisconnect)
271 return;
272
273 const key = `${message.address}:${message.port}:${message.addressType}:` +
274 `${message.fd}` + (message.port === 0 ? `:${message.index}` : '');
275 const cachedHandle = handles.get(key);
276 let handle;
277 if (cachedHandle && !cachedHandle.has(worker)) {
278 handle = cachedHandle;
279 }
280
281 if (handle === undefined) {
282 let address = message.address;
283
284 // Find shortest path for unix sockets because of the ~100 byte limit
285 if (message.port < 0 && typeof address === 'string' &&
286 process.platform !== 'win32') {
287
288 address = path.relative(process.cwd(), address);
289
290 if (message.address.length < address.length)
291 address = message.address;
292 }
293
294 // UDP is exempt from round-robin connection balancing for what should
295 // be obvious reasons: it's connectionless. There is nothing to send to
296 // the workers except raw datagrams and that's pointless.
297 if (schedulingPolicy !== SCHED_RR ||
298 message.addressType === 'udp4' ||
299 message.addressType === 'udp6') {
300 handle = new SharedHandle(key, address, message);
301 } else {
302 handle = new RoundRobinHandle(key, address, message);
303 }
304
305 if (!cachedHandle) {
306 handles.set(key, handle);
307 }
308 }
309
310 handle.data ||= message.data;
311
312 // Set custom server data
313 handle.add(worker, (errno, reply, serverHandle) => {
314 if (!errno) {
315 handles.set(key, handle); // Update in case it was replaced.
316 }
317 const { data } = handles.get(key);
318 if (!cachedHandle && errno) {
319 handles.delete(key);
320 }
321
322 send(worker, {
323 errno,
324 key,
325 ack: message.seq,

Callers

nothing calls this directly

Calls 6

sendFunction · 0.70
getMethod · 0.65
hasMethod · 0.65
addMethod · 0.65
deleteMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected