Title: [Bug]: StackOverflowError when a page makes thousands of requests under a route · Issue #2068 · microsoft/playwright-java · GitHub
Open Graph Title: [Bug]: StackOverflowError when a page makes thousands of requests under a route · Issue #2068 · microsoft/playwright-java
X Title: [Bug]: StackOverflowError when a page makes thousands of requests under a route · Issue #2068 · microsoft/playwright-java
Description: Version 1.65.1 (also 1.64.0) Steps to reproduce Save the file below as RouteBurst.java and run it with the Playwright jars on the classpath: java -cp "
Open Graph Description: Version 1.65.1 (also 1.64.0) Steps to reproduce Save the file below as RouteBurst.java and run it with the Playwright jars on the classpath: java -cp "
X Description: Version 1.65.1 (also 1.64.0) Steps to reproduce Save the file below as RouteBurst.java and run it with the Playwright jars on the classpath: java -cp "<playwright 1.65.1 classpath>"...
Opengraph URL: https://github.com/microsoft/playwright-java/issues/2068
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: StackOverflowError when a page makes thousands of requests under a route","articleBody":"### Version\n\n1.65.1 (also 1.64.0)\n\n### Steps to reproduce\n\nSave the file below as `RouteBurst.java` and run it with the Playwright jars on the classpath:\n\n```\njava -cp \"\u003cplaywright 1.65.1 classpath>\" RouteBurst.java 3000\n```\n\n```java\nimport com.microsoft.playwright.*;\nimport com.sun.net.httpserver.HttpServer;\nimport java.net.InetSocketAddress;\nimport java.nio.charset.StandardCharsets;\nimport java.util.concurrent.Executors;\n\npublic class RouteBurst {\n public static void main(String[] args) throws Exception {\n int n = args.length > 0 ? Integer.parseInt(args[0]) : 3000;\n boolean routed = args.length \u003c 2 || !\"noroute\".equals(args[1]);\n HttpServer server = HttpServer.create(new InetSocketAddress(\"127.0.0.1\", 0), 0);\n server.createContext(\"/r\", ex -> {\n byte[] body = \"ok\".getBytes(StandardCharsets.UTF_8);\n ex.sendResponseHeaders(200, body.length);\n ex.getResponseBody().write(body);\n ex.close();\n });\n server.createContext(\"/\", ex -> {\n String html = \"\u003cscript>window.done = false;\"\n + \"Promise.allSettled(Array.from({length: \" + n + \"}, (_, i) => fetch('/r?i=' + i)))\"\n + \".then(() => { window.done = true; });\u003c/script>\";\n byte[] body = html.getBytes(StandardCharsets.UTF_8);\n ex.getResponseHeaders().add(\"Content-Type\", \"text/html\");\n ex.sendResponseHeaders(200, body.length);\n ex.getResponseBody().write(body);\n ex.close();\n });\n server.setExecutor(Executors.newFixedThreadPool(16));\n server.start();\n int[] handled = {0};\n try (Playwright playwright = Playwright.create()) {\n Browser browser = playwright.chromium().launch();\n Page page = browser.newPage();\n if (routed) {\n page.route(\"**/*\", route -> { handled[0]++; route.resume(); });\n }\n page.navigate(\"http://localhost:\" + server.getAddress().getPort() + \"/\");\n page.waitForFunction(\"window.done === true\");\n System.out.println(\"OK requests=\" + n + \" handled=\" + handled[0]);\n } catch (StackOverflowError e) {\n System.out.println(\"StackOverflowError requests=\" + n + \" handled=\" + handled[0]);\n } finally {\n server.stop(0);\n }\n System.exit(0);\n }\n}\n```\n\nThe page makes 3000 `fetch` calls. One `page.route(\"**/*\", ...)` handler resumes each request.\n\n### Expected behavior\n\n`OK requests=3000 handled=3001`, as for 1000 requests.\n\n### Actual behavior\n\n```\nStackOverflowError requests=3000 handled=1554\n```\n\n5 of 5 runs fail, each after about 1550 handled routes. Without the route (`RouteBurst.java 3000 noroute`) the run passes. The same occurs with `browserContext.route`.\n\nWith a pool of 100 workers in the page in place of one burst, the failure is intermittent (2 of 6 runs at 5000 to 10000 requests), because the depth depends on how many route events are in the queue.\n\n### Cause\n\nAfter each handled route, `PageImpl.handleEvent` and `BrowserContextImpl.handleRoute` call `updateInterceptionPatterns()`. That call sends `setNetworkInterceptionPatterns` and blocks until the answer arrives. While it blocks, `runUntil` dispatches the next message, which is the next `route` event. So each queued route event runs one level deeper on the same stack. A stack trace from inside the handler (1.65.1) shows the cycle:\n\n```\nuser handler\ncom.microsoft.playwright.impl.Router$RouteInfo.handle(Router.java:48)\ncom.microsoft.playwright.impl.Router.handle(Router.java:86)\ncom.microsoft.playwright.impl.PageImpl.handleEvent(PageImpl.java:226)\ncom.microsoft.playwright.impl.Connection.dispatch(Connection.java:347)\ncom.microsoft.playwright.impl.Connection.processOneMessage(Connection.java:261)\ncom.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:154)\ncom.microsoft.playwright.impl.Connection.sendMessage(Connection.java:157)\ncom.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:142)\ncom.microsoft.playwright.impl.PageImpl.updateInterceptionPatterns(PageImpl.java:1438)\ncom.microsoft.playwright.impl.PageImpl.handleEvent(PageImpl.java:229)\ncom.microsoft.playwright.impl.Connection.dispatch(Connection.java:347)\ncom.microsoft.playwright.impl.Connection.processOneMessage(Connection.java:261)\n... the same 7 frames again for each queued route event\n```\n\nThis is the defect class of #678, where `Route.resume` and `Route.abort` stopped waiting for the answer. The pattern update after each route still waits.\n\nThe Node.js client does this differently in `Page._onRoute`: it updates the patterns only when no route remains, and it does not wait for the answer:\n\n```ts\nif (!this._routes.length)\n this._updateInterceptionPatterns({ internal: true }).catch(() => {});\n```\n\nA possible fix is the same condition in Java (send the update only when the set of patterns changed, for example when a handler with `times` expired), or a send that does not wait.\n\nA second effect makes it worse: when `PLAYWRIGHT_JAVA_SRC` is set, each API call captures a stack trace, and the cost of that grows with the nesting depth. Then the client falls further behind and the nesting grows faster.\n\n### Additional context\n\nFound through https://github.com/Blockether/spel/issues/135, where a daemon with one catch-all route failed on pages with many requests. A workaround for a client is a route pattern that matches fewer requests, or a thread with a larger stack.\n\n### Environment\n\n- Operating System: macOS 27.2.1 (arm64)\n- JDK: OpenJDK 25.0.3\n- Browser: Chromium (bundled with 1.65.1), headless\n","author":{"url":"https://github.com/kwojcik-blockether","@type":"Person","name":"kwojcik-blockether"},"datePublished":"2026-11-21T23:26:03Z","url":"https://github.com/microsoft/playwright-java/issues/2068"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6285fab9-3506-6afa-6dc3-a41f8e67a827 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A834:560C3:3CE284:539234:6B04BFB6 |
| html-safe-nonce | 222b4373244daf27de7df4c00f80a84c450c31124cc941bb5e0f892b2dfb73c7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODM0OjU2MEMzOjNDRTI4NDo1MzkyMzQ6NkIwNEJGQjYiLCJ2aXNpdG9yX2lkIjoiNTkzMTQxMDMxOTMwMDkzNTYwNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8a07b085cc10685d738204fb9ea39001d99c33bad596fc1697e6095876ff683c |
| hovercard-subject-tag | issue:6535760317 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/playwright-java/2068/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cc1b063a8c76e4a382ca14580a28a583ce4697398f571aeb1eb6cf903963093f/microsoft/playwright-java/issues/2068 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cc1b063a8c76e4a382ca14580a28a583ce4697398f571aeb1eb6cf903963093f/microsoft/playwright-java/issues/2068 |
| og:image:alt | Version 1.65.1 (also 1.64.0) Steps to reproduce Save the file below as RouteBurst.java and run it with the Playwright jars on the classpath: java -cp " |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kwojcik-blockether |
| hostname | github.com |
| expected-hostname | github.com |
| None | 85dd75377eb77313206b8fc108bcee6a3a029286d94bf32bf9b4426e4d92e0c4 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/playwright-java git https://github.com/microsoft/playwright-java.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 298640027 |
| octolytics-dimension-repository_nwo | microsoft/playwright-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 298640027 |
| octolytics-dimension-repository_network_root_nwo | microsoft/playwright-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0d64fa748a2bab9a5b587a967ac4da1cfa8da6dd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width