Repository: facebook/react
Pull request: [Flight] Fix stack overflow in `visitAsyncNode` with deep async chains

Database libraries like Gel/EdgeDB can create very long linear chains of async sequences through temporal async sequencing in connection pools. The recursive traversal of `node.previous` chains in `visitAsyncNode` causes stack overflow on these deep chains.

The fix converts the `previous` chain traversal from recursive to iterative. We collect the chain into an array, then process from deepest to shallowest.

The `awaited` traversal remains recursive since its depth is bounded by promise dependency depth, not by the number of event loop turns. Each `awaited` branch still benefits from the iterative `previous` handling within its own traversal.

I've verified that this fixes the [repro](https://github.com/jere-co/next-debug) provided in #35246.

closes #35246

Changed files:
filename: packages/react-server/src/ReactFlightServer.js
patch: @@ -2345,19 +2345,53 @@ function visitAsyncNode(
   >,
   cutOff: number,
 ): void | null | PromiseNode | IONode {
-  if (visited.has(node)) {
-    // It's possible to visit them same node twice when it's part of both an "awaited" path
-    // and a "previous" path. This also gracefully handles cycles which would be a bug.
-    return visited.get(node);
-  }
-  // Set it as visited early in case we see ourselves before returning.
-  visited.set(node, null);
-  const result = visitAsyncNodeImpl(request, task, node, visited, cutOff);
-  if (result !== null) {
-    // If we ended up with a value, let's use that value for future visits.
-    visited.set(node, result);
+  // Collect the previous chain iteratively instead of recursively to avoid
+  // stack overflow on deep chains. We process from deepest to shallowest so
+  // each node has its previousIONode available.
+  const chain: Array<AsyncSequence> = [];
+  let current: AsyncSequence | null = node;
+
+  while (current !== null) {
+    if (visited.has(current)) {
+      break;
+    }
+    chain.push(current);
+    current = current.previous;
   }
-  return result;
+
+  let previousIONode: void | null | PromiseNode | IONode =
+    current !== null ? visited.get(current) : null;
+
+  // Process from deepest to shallowest (reverse order).
+  for (let i = chain.length - 1; i >= 0; i--) {
+    const n = chain[i];
+    // Set it as visited early in case we see the node again before returning.
+    visited.set(n, null);
+
+    const result = visitAsyncNodeImpl(
+      request,
+      task,
+      n,
+      visited,
+      cutOff,
+      previousIONode,
+    );
+
+    if (result !== null) {
+      // If we ended up with a value, let's use that value for future visits.
+      visited.set(n, result);
+    }
+
+    if (result === undefined) {
+      // Undefined is used as a signal that we found a suitable aborted node
+      // and we don't have to find further aborted nodes.
+      return undefined;
+    }
+
+    previousIONode = result;
+  }
+
+  return previousIONode;
 }
 
 function visitAsyncNodeImpl(
@@ -2369,6 +2403,7 @@ function visitAsyncNodeImpl(
     void | null | PromiseNode | IONode,
   >,
   cutOff: number,
+  previousIONode: void | null | PromiseNode | IONode,
 ): void | null | PromiseNode | IONode {
   if (node.end >= 0 && node.end <= request.timeOrigin) {
     // This was already resolved when we started this render. It must have been either something
@@ -2377,23 +2412,6 @@ function visitAsyncNodeImpl(
     return null;
   }
 
-  let previousIONode: void | null | PromiseNode | IONode = null;
-  // First visit anything that blocked this sequence to start in the first place.
-  if (node.previous !== null) {
-    previousIONode = visitAsyncNode(
-      request,
-      task,
-      node.previous,
-      visited,
-      cutOff,
-    );
-    if (previousIONode === undefined) {
-      // Undefined is used as a signal that we found a suitable aborted node and we don't have to find
-      // further aborted nodes.
-      return undefined;
-    }
-  }
-
   // `found` represents the return value of the following switch statement.
   // We can't use multiple `return` statements in the switch statement
   // since that prevents Closure compiler from inlining `visitAsyncImpl`

filename: packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js
patch: @@ -5,6 +5,7 @@
 
 import {patchSetImmediate} from '../../../../scripts/jest/patchSetImmediate';
 
+import crypto from 'crypto';
 import fs from 'fs/promises';
 import path from 'path';
 
@@ -160,9 +161,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                129,
+                130,
+                109,
                 109,
-                108,
                 50,
               ],
             ],
@@ -184,9 +185,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    129,
+                    130,
+                    109,
                     109,
-                    108,
                     50,
                   ],
                 ],
@@ -195,25 +196,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  110,
+                  111,
                   13,
-                  109,
+                  110,
                   5,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  118,
+                  119,
                   26,
-                  117,
+                  118,
                   5,
                 ],
               ],
@@ -232,9 +233,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  129,
+                  130,
+                  109,
                   109,
-                  108,
                   50,
                 ],
               ],
@@ -243,17 +244,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "getData",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                110,
+                111,
                 13,
-                109,
+                110,
                 5,
               ],
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                118,
+                119,
                 26,
-                117,
+                118,
                 5,
               ],
             ],
@@ -278,9 +279,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    129,
+                    130,
+                    109,
                     109,
-                    108,
                     50,
                   ],
                 ],
@@ -289,25 +290,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  111,
+                  112,
                   21,
-                  109,
+                  110,
                   5,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  118,
+                  119,
                   20,
-                  117,
+                  118,
                   5,
                 ],
               ],
@@ -326,9 +327,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  129,
+                  130,
+                  109,
                   109,
-                  108,
                   50,
                 ],
               ],
@@ -337,17 +338,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "getData",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                113,
+                114,
                 21,
-                109,
+                110,
                 5,
               ],
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                118,
+                119,
                 20,
-                117,
+                118,
                 5,
               ],
             ],
@@ -367,9 +368,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                120,
+                121,
                 60,
-                117,
+                118,
                 5,
               ],
             ],
@@ -391,9 +392,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    129,
+                    130,
+                    109,
                     109,
-                    108,
                     50,
                   ],
                 ],
@@ -402,17 +403,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  111,
+                  112,
                   21,
-                  109,
+                  110,
                   5,
                 ],
               ],
@@ -431,9 +432,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  120,
+                  121,
                   60,
-                  117,
+                  118,
                   5,
                 ],
               ],
@@ -442,9 +443,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "InnerComponent",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                126,
+                127,
                 35,
-                123,
+                124,
                 5,
               ],
             ],
@@ -625,9 +626,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                589,
+                590,
                 40,
-                570,
+                571,
                 49,
               ],
               [
@@ -657,9 +658,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    589,
+                    590,
                     40,
-                    570,
+                    571,
                     49,
                   ],
                   [
@@ -676,25 +677,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  572,
+                  573,
                   13,
-                  571,
+                  572,
                   5,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  577,
+                  578,
                   36,
-                  576,
+                  577,
                   5,
                 ],
               ],
@@ -713,9 +714,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  589,
+                  590,
                   40,
-                  570,
+                  571,
                   49,
                 ],
                 [
@@ -732,17 +733,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "getData",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                572,
+                573,
                 13,
-                571,
+                572,
                 5,
               ],
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                577,
+                578,
                 36,
-                576,
+                577,
                 5,
               ],
             ],
@@ -762,9 +763,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                579,
+                580,
                 60,
-                576,
+                577,
                 5,
               ],
             ],
@@ -783,9 +784,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    589,
+                    590,
                     40,
-                    570,
+                    571,
                     49,
                   ],
                   [
@@ -802,25 +803,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  572,
+                  573,
                   13,
-                  571,
+                  572,
                   5,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  578,
+                  579,
                   22,
-                  576,
+                  577,
                   5,
                 ],
               ],
@@ -839,9 +840,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  579,
+                  580,
                   60,
-                  576,
+                  577,
                   5,
                 ],
               ],
@@ -850,9 +851,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "InnerComponent",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                585,
+                586,
                 40,
-                582,
+                583,
                 5,
               ],
             ],
@@ -927,9 +928,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                896,
+                897,
                 109,
-                883,
+                884,
                 80,
               ],
             ],
@@ -948,9 +949,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    896,
+                    897,
                     109,
-                    883,
+                    884,
                     80,
                   ],
                 ],
@@ -967,9 +968,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  896,
+                  897,
                   109,
-                  883,
+                  884,
                   80,
                 ],
               ],
@@ -1041,9 +1042,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1010,
+                1011,
                 109,
-                1001,
+                1002,
                 94,
               ],
             ],
@@ -1114,9 +1115,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1083,
+                1084,
                 109,
-                1059,
+                1060,
                 50,
               ],
             ],
@@ -1198,9 +1199,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1167,
+                1168,
                 109,
-                1150,
+                1151,
                 63,
               ],
             ],
@@ -1217,17 +1218,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "fetchThirdParty",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                93,
+                94,
                 40,
-                91,
+                92,
                 3,
               ],
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1163,
+                1164,
                 24,
-                1162,
+                1163,
                 5,
               ],
             ],
@@ -1249,17 +1250,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "fetchThirdParty",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    93,
+                    94,
                     40,
-                    91,
+                    92,
                     3,
                   ],
                   [
                     "Component",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    1163,
+                    1164,
                     24,
-                    1162,
+                    1163,
                     5,
                   ],
                 ],
@@ -1268,25 +1269,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1152,
+                  1153,
                   13,
-                  1151,
+                  1152,
                   5,
                 ],
                 [
                   "ThirdPartyComponent",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1158,
+                  1159,
                   24,
-                  1157,
+                  1158,
                   5,
                 ],
               ],
@@ -1305,17 +1306,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "fetchThirdParty",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  93,
+                  94,
                   40,
-                  91,
+                  92,
                   3,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1163,
+                  1164,
                   24,
-                  1162,
+                  1163,
                   5,
                 ],
               ],
@@ -1324,17 +1325,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "getData",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1152,
+                1153,
                 13,
-                1151,
+                1152,
                 5,
               ],
               [
                 "ThirdPartyComponent",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1158,
+                1159,
                 24,
-                1157,
+                1158,
                 5,
               ],
             ],
@@ -1359,17 +1360,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "fetchThirdParty",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    93,
+                    94,
                     40,
-                    91,
+                    92,
                     3,
                   ],
                   [
                     "Component",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    1163,
+                    1164,
                     24,
-                    1162,
+                    1163,
                     5,
                   ],
                 ],
@@ -1378,25 +1379,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1153,
+                  1154,
                   13,
-                  1151,
+                  1152,
                   5,
                 ],
                 [
                   "ThirdPartyComponent",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1158,
+                  1159,
                   18,
-                  1157,
+                  1158,
                   5,
                 ],
               ],
@@ -1415,17 +1416,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "fetchThirdParty",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  93,
+                  94,
                   40,
-                  91,
+                  92,
                   3,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1163,
+                  1164,
                   24,
-                  1162,
+                  1163,
                   5,
                 ],
               ],
@@ -1434,17 +1435,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "getData",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1153,
+                1154,
                 13,
-                1151,
+                1152,
                 5,
               ],
               [
                 "ThirdPartyComponent",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1158,
+                1159,
                 18,
-                1157,
+                1158,
                 5,
               ],
             ],
@@ -1544,9 +1545,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1508,
+                1509,
                 40,
-                1491,
+                1492,
                 62,
               ],
               [
@@ -1576,9 +1577,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    1508,
+                    1509,
                     40,
-                    1491,
+                    1492,
                     62,
                   ],
                   [
@@ -1595,25 +1596,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1493,
+                  1494,
                   13,
-                  1492,
+                  1493,
                   25,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1503,
+                  1504,
                   13,
-                  1502,
+                  1503,
                   5,
                 ],
               ],
@@ -1632,9 +1633,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1508,
+                  1509,
                   40,
-                  1491,
+                  1492,
                   62,
                 ],
                 [
@@ -1651,17 +1652,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "getData",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1493,
+                1494,
                 13,
-                1492,
+                1493,
                 25,
               ],
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1503,
+                1504,
                 13,
-                1502,
+                1503,
                 5,
               ],
             ],
@@ -1681,9 +1682,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1504,
+                1505,
                 60,
-                1502,
+                1503,
                 5,
               ],
             ],
@@ -1705,9 +1706,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    1508,
+                    1509,
                     40,
-                    1491,
+                    1492,
                     62,
                   ],
                   [
@@ -1724,25 +1725,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1493,
+                  1494,
                   13,
-                  1492,
+                  1493,
                   25,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1503,
+                  1504,
                   13,
-                  1502,
+                  1503,
                   5,
                 ],
               ],
@@ -1761,9 +1762,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1504,
+                  1505,
                   60,
-                  1502,
+                  1503,
                   5,
                 ],
               ],
@@ -1772,9 +1773,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Child",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1498,
+                1499,
                 28,
-                1497,
+                1498,
                 5,
               ],
             ],
@@ -1857,9 +1858,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1821,
+                1822,
                 40,
-                1805,
+                1806,
                 57,
               ],
               [
@@ -1889,9 +1890,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    1821,
+                    1822,
                     40,
-                    1805,
+                    1806,
                     57,
                   ],
                   [
@@ -1908,25 +1909,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1807,
+                  1808,
                   13,
-                  1806,
+                  1807,
                   25,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1816,
+                  1817,
                   23,
-                  1815,
+                  1816,
                   5,
                 ],
               ],
@@ -1945,9 +1946,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1821,
+                  1822,
                   40,
-                  1805,
+                  1806,
                   57,
                 ],
                 [
@@ -1964,17 +1965,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "getData",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1807,
+                1808,
                 13,
-                1806,
+                1807,
                 25,
               ],
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1816,
+                1817,
                 23,
-                1815,
+                1816,
                 5,
               ],
             ],
@@ -1994,9 +1995,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1817,
+                1818,
                 60,
-                1815,
+                1816,
                 5,
               ],
             ],
@@ -2015,9 +2016,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    1821,
+                    1822,
                     40,
-                    1805,
+                    1806,
                     57,
                   ],
                   [
@@ -2034,25 +2035,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1807,
+                  1808,
                   13,
-                  1806,
+                  1807,
                   25,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  1816,
+                  1817,
                   23,
-                  1815,
+                  1816,
                   5,
                 ],
               ],
@@ -2066,9 +2067,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                1817,
+                1818,
                 60,
-                1815,
+                1816,
                 5,
               ],
             ],
@@ -2153,9 +2154,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2117,
+                2118,
                 40,
-                2099,
+                2100,
                 80,
               ],
               [
@@ -2185,9 +2186,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    2117,
+                    2118,
                     40,
-                    2099,
+                    2100,
                     80,
                   ],
                   [
@@ -2204,25 +2205,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "delayTrice",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2107,
+                  2108,
                   13,
-                  2105,
+                  2106,
                   5,
                 ],
                 [
                   "Bar",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2112,
+                  2113,
                   13,
-                  2111,
+                  2112,
                   5,
                 ],
               ],
@@ -2241,9 +2242,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2117,
+                  2118,
                   40,
-                  2099,
+                  2100,
                   80,
                 ],
                 [
@@ -2260,17 +2261,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "delayTrice",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2107,
+                2108,
                 13,
-                2105,
+                2106,
                 5,
               ],
               [
                 "Bar",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2112,
+                2113,
                 13,
-                2111,
+                2112,
                 5,
               ],
             ],
@@ -2292,9 +2293,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    2117,
+                    2118,
                     40,
-                    2099,
+                    2100,
                     80,
                   ],
                   [
@@ -2311,33 +2312,33 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "delayTwice",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2101,
+                  2102,
                   13,
-                  2100,
+                  2101,
                   5,
                 ],
                 [
                   "delayTrice",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2106,
+                  2107,
                   15,
-                  2105,
+                  2106,
                   5,
                 ],
                 [
                   "Bar",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2112,
+                  2113,
                   13,
-                  2111,
+                  2112,
                   5,
                 ],
               ],
@@ -2356,9 +2357,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2117,
+                  2118,
                   40,
-                  2099,
+                  2100,
                   80,
                 ],
                 [
@@ -2375,25 +2376,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "delayTwice",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2101,
+                2102,
                 13,
-                2100,
+                2101,
                 5,
               ],
               [
                 "delayTrice",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2106,
+                2107,
                 15,
-                2105,
+                2106,
                 5,
               ],
               [
                 "Bar",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2112,
+                2113,
                 13,
-                2111,
+                2112,
                 5,
               ],
             ],
@@ -2415,9 +2416,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    2117,
+                    2118,
                     40,
-                    2099,
+                    2100,
                     80,
                   ],
                   [
@@ -2434,17 +2435,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "delayTwice",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2102,
+                  2103,
                   13,
-                  2100,
+                  2101,
                   5,
                 ],
               ],
@@ -2463,9 +2464,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2117,
+                  2118,
                   40,
-                  2099,
+                  2100,
                   80,
                 ],
                 [
@@ -2482,9 +2483,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "delayTwice",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2102,
+                2103,
                 13,
-                2100,
+                2101,
                 5,
               ],
             ],
@@ -2557,9 +2558,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2526,
+                2527,
                 109,
-                2515,
+                2516,
                 58,
               ],
             ],
@@ -2581,9 +2582,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    2526,
+                    2527,
                     109,
-                    2515,
+                    2516,
                     58,
                   ],
                 ],
@@ -2592,25 +2593,25 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "getData",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2517,
+                  2518,
                   14,
-                  2516,
+                  2517,
                   5,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2523,
+                  2524,
                   20,
-                  2522,
+                  2523,
                   5,
                 ],
               ],
@@ -2629,9 +2630,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2526,
+                  2527,
                   109,
-                  2515,
+                  2516,
                   58,
                 ],
               ],
@@ -2640,17 +2641,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "getData",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2517,
+                2518,
                 23,
-                2516,
+                2517,
                 5,
               ],
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2523,
+                2524,
                 20,
-                2522,
+                2523,
                 5,
               ],
             ],
@@ -2729,9 +2730,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2693,
+                2694,
                 40,
-                2681,
+                2682,
                 56,
               ],
               [
@@ -2761,9 +2762,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    2693,
+                    2694,
                     40,
-                    2681,
+                    2682,
                     56,
                   ],
                   [
@@ -2780,17 +2781,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "delay",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  86,
+                  87,
                   12,
-                  85,
+                  86,
                   3,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2689,
+                  2690,
                   20,
-                  2688,
+                  2689,
                   5,
                 ],
               ],
@@ -2809,9 +2810,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2693,
+                  2694,
                   40,
-                  2681,
+                  2682,
                   56,
                 ],
                 [
@@ -2828,9 +2829,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2689,
+                2690,
                 20,
-                2688,
+                2689,
                 5,
               ],
             ],
@@ -2923,9 +2924,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2882,
+                2883,
                 40,
-                2861,
+                2862,
                 42,
               ],
               [
@@ -2955,9 +2956,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    2882,
+                    2883,
                     40,
-                    2861,
+                    2862,
                     42,
                   ],
                   [
@@ -2974,17 +2975,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2868,
+                  2869,
                   15,
-                  2867,
+                  2868,
                   15,
                 ],
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2877,
+                  2878,
                   19,
-                  2876,
+                  2877,
                   5,
                 ],
               ],
@@ -3003,9 +3004,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2882,
+                  2883,
                   40,
-                  2861,
+                  2862,
                   42,
                 ],
                 [
@@ -3022,17 +3023,17 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2868,
+                2869,
                 15,
-                2867,
+                2868,
                 15,
               ],
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2877,
+                2878,
                 19,
-                2876,
+                2877,
                 5,
               ],
             ],
@@ -3054,9 +3055,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    2882,
+                    2883,
                     40,
-                    2861,
+                    2862,
                     42,
                   ],
                   [
@@ -3073,9 +3074,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2877,
+                  2878,
                   25,
-                  2876,
+                  2877,
                   5,
                 ],
               ],
@@ -3094,9 +3095,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  2882,
+                  2883,
                   40,
-                  2861,
+                  2862,
                   42,
                 ],
                 [
@@ -3113,9 +3114,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                2877,
+                2878,
                 25,
-                2876,
+                2877,
                 5,
               ],
             ],
@@ -3191,9 +3192,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Object.<anonymous>",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                3158,
+                3159,
                 19,
-                3146,
+                3147,
                 36,
               ],
             ],
@@ -3215,9 +3216,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                   [
                     "Object.<anonymous>",
                     "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                    3158,
+                    3159,
                     19,
-                    3146,
+                    3147,
                     36,
                   ],
                 ],
@@ -3226,9 +3227,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Component",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  3150,
+                  3151,
                   7,
-                  3148,
+                  3149,
                   5,
                 ],
               ],
@@ -3247,9 +3248,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
                 [
                   "Object.<anonymous>",
                   "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                  3158,
+                  3159,
                   19,
-                  3146,
+                  3147,
                   36,
                 ],
               ],
@@ -3258,9 +3259,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                3152,
+                3153,
                 7,
-                3148,
+                3149,
                 5,
               ],
             ],
@@ -3385,9 +3386,9 @@ describe('ReactFlightAsyncDebugInfo', () => {
               [
                 "Component",
                 "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
-                3303,
+                3304,
                 20,
-                3302,
+                3303,
                 5,
               ],
             ],
@@ -3402,4 +3403,234 @@ describe('ReactFlightAsyncDebugInfo', () => {
       `);
     }
   });
+
+  // Regression test: Database clients like Gel/EdgeDB with connection pools can
+  // create very long chains of async nodes linked via `previous` pointers.
+  // visitAsyncNode must handle chains of thousands of nodes without stack
+  // overflow.
+  //
+  // The pattern that creates deep chains (Event/messageWaiter):
+  // 1. Create a Promise resolved by an I/O callback
+  // 2. Start I/O, await the Promise
+  // 3. When I/O resolves, code continues in the callback context
+  // 4. The next iteration's async nodes link via `previous` to the current
+  //    context
+  it('handles deep linear async chains from connection pool patterns', async () => {
+    // Replicate Gel's Event class pattern, a Promise resolved externally by I/O
+    class Event {
+      constructor() {
+        this._resolve = null;
+        this._promise = new Promise(resolve => {
+          this._resolve = resolve;
+        });
+      }
+
+      wait() {
+        return this._promise;
+      }
+
+      set() {
+        this._resolve(true);
+      }
+    }
+
+    // Replicate Gel's _waitForMessage pattern:
+    // Each iteration creates an Event, schedules I/O to resolve it, and awaits.
+    // The next iteration runs in the context of the previous I/O callback,
+    // creating linear chains of previous pointers.
+    async function buildLinearChain(depth) {
+      for (let i = 0; i < depth; i++) {
+        const event = new Event();
+        // crypto.randomBytes uses the thread pool and is recognized as I/O
+        // (type='RANDOMBYTESREQUEST'). It's much faster than setTimeout.
+        crypto.randomBytes(1, () => event.set());
+        await event.wait();
+        // After this await resolves, we're in the crypto callback's context
+        // The next Event will be created in this context, linking prev pointers
+      }
+    }
+
+    async function Component() {
+      // Use 2000 iterations to ensure regression would be caught. Using
+      // crypto.randomBytes keeps the test fast.
+      await buildLinearChain(2000);
+      return 'done';
+    }
+
+    const stream = ReactServerDOMServer.renderToPipeableStream(
+      <Component />,
+      {},
+      {
+        filterStackFrame: (filename, functionName) => {
+          // Custom filter that treats Event and buildLinearChain as library
+          // code. This simulates how real DB libraries like Gel/EdgeDB would be
+          // filtered.
+          if (
+            functionName === 'new Event' ||
+            functionName === 'buildLinearChain' ||
+            functionName === '_loop' // Generated name for the for-loop
+          ) {
+            return false;
+          }
+          return filterStackFrame(filename, functionName);
+        },
+      },
+    );
+
+    const readable = new Stream.PassThrough(streamOptions);
+
+    const result = ReactServerDOMClient.createFromNodeStream(readable, {
+      moduleMap: {},
+      moduleLoading: {},
+    });
+    stream.pipe(readable);
+
+    // This should not throw "Maximum call stack size exceeded"
+    expect(await result).toBe('done');
+
+    await finishLoadingStream(readable);
+    if (
+      __DEV__ &&
+      gate(
+        flags =>
+          flags.enableComponentPerformanceTrack && flags.enableAsyncDebugInfo,
+      )
+    ) {
+      // With library code filtered out, we should only see the Component's
+      // debug info, not thousands of entries from the internal
+      // Event/buildLinearChain operations.
+      expect(getDebugInfo(result)).toMatchInlineSnapshot(`
+        [
+          {
+            "time": 0,
+          },
+          {
+            "env": "Server",
+            "key": null,
+            "name": "Component",
+            "props": {},
+            "stack": [
+              [
+                "Object.<anonymous>",
+                "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
+                3461,
+                40,
+                3418,
+                72,
+              ],
+              [
+                "new Promise",
+                "",
+                0,
+                0,
+                0,
+                0,
+              ],
+            ],
+          },
+          {
+            "time": 0,
+          },
+          {
+            "awaited": {
+              "end": 0,
+              "env": "Server",
+              "name": "buildLinearChain",
+              "owner": {
+                "env": "Server",
+                "key": null,
+                "name": "Component",
+                "props": {},
+                "stack": [
+                  [
+                    "Object.<anonymous>",
+                    "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
+                    3461,
+                    40,
+                    3418,
+                    72,
+                  ],
+                  [
+                    "new Promise",
+                    "",
+                    0,
+                    0,
+                    0,
+                    0,
+                  ],
+                ],
+              },
+              "stack": [
+                [
+                  "Component",
+                  "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
+                  3456,
+                  13,
+                  3453,
+                  5,
+                ],
+              ],
+              "start": 0,
+              "value": {
+                "value": undefined,
+              },
+            },
+            "env": "Server",
+            "owner": {
+              "env": "Server",
+              "key": null,
+              "name": "Component",
+              "props": {},
+              "stack": [
+                [
+                  "Object.<anonymous>",
+                  "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
+                  3461,
+                  40,
+                  3418,
+                  72,
+                ],
+                [
+                  "new Promise",
+                  "",
+                  0,
+                  0,
+                  0,
+                  0,
+                ],
+              ],
+            },
+            "stack": [
+              [
+                "Component",
+                "/packages/react-server/src/__tests__/ReactFlightAsyncDebugInfo-test.js",
+                3456,
+                13,
+                3453,
+                5,
+              ],
+            ],
+          },
+          {
+            "time": 0,
+          },
+          {
+            "time": 0,
+          },
+          {
+            "awaited": {
+              "byteSize": 0,
+              "end": 0,
+              "name": "rsc stream",
+              "owner": null,
+              "start": 0,
+              "value": {
+                "value": "stream",
+              },
+            },
+          },
+        ]
+      `);
+    }
+  });
 });