Skip to content

Fix unhandled exception on blockResources#778

Open
turicas wants to merge 2 commits intoprerender:masterfrom
PythonicCafe:fix/blockResources-exception
Open

Fix unhandled exception on blockResources#778
turicas wants to merge 2 commits intoprerender:masterfrom
PythonicCafe:fix/blockResources-exception

Conversation

@turicas
Copy link
Copy Markdown

@turicas turicas commented Feb 24, 2024

Hello! After running a custom server.js with many plugins enabled, I've got an exception and the server just died, as you can see in the logs below:

[...]
2024-02-24T13:37:10.707Z Started Chrome: HeadlessChrome/122.0.6261.57
2024-02-24T13:37:11.853Z getting https://brasil.io/
2024-02-24T13:37:11.932Z + 1 https://brasil.io/
2024-02-24T13:37:11.933Z Initial request to https://brasil.io/
2024-02-24T13:37:13.284Z + 2 https://brasil.io/home/
2024-02-24T13:37:13.285Z Initial request redirected from https://brasil.io/home/ with status code 302
2024-02-24T13:37:13.291Z - 0 https://brasil.io/home/
/app/node_modules/chrome-remote-interface/lib/chrome.js:94
                                : new ProtocolError(request, response)
                                  ^

ProtocolError: Invalid InterceptionId.
    at /app/node_modules/chrome-remote-interface/lib/chrome.js:94:35
    at Chrome._handleMessage (/app/node_modules/chrome-remote-interface/lib/chrome.js:257:17)
    at WebSocket.<anonymous> (/app/node_modules/chrome-remote-interface/lib/chrome.js:235:22)
    at WebSocket.emit (node:events:519:28)
    at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:1068:20)
    at Receiver.emit (node:events:519:28)
    at Receiver.dataMessage (/app/node_modules/ws/lib/receiver.js:517:14)
    at /app/node_modules/ws/lib/receiver.js:468:23
    at /app/node_modules/ws/lib/permessage-deflate.js:308:9
    at /app/node_modules/ws/lib/permessage-deflate.js:391:7 {
  request: {
    method: 'Network.continueInterceptedRequest',
    params: { interceptionId: 'interception-job-1.1' },
    sessionId: undefined
  },
  response: { code: -32602, message: 'Invalid InterceptionId.' }
}

Node.js v21.6.2

Upon investigating, I identified that the exception was caused by the Network.continueInterceptedRequest call in plugins/blockResources.js. To prevent the server from crashing, I added a catch to just log the exception. Logs after the change:

[...]
2024-02-24T13:38:52.232Z Started Chrome: HeadlessChrome/122.0.6261.57
2024-02-24T13:38:58.349Z getting https://brasil.io/
2024-02-24T13:38:58.444Z + 1 https://brasil.io/
2024-02-24T13:38:58.445Z Initial request to https://brasil.io/
2024-02-24T13:38:58.893Z + 2 https://brasil.io/home/
2024-02-24T13:38:58.894Z Initial request redirected from https://brasil.io/home/ with status code 302
2024-02-24T13:38:58.900Z - 0 https://brasil.io/home/
[blockResources] Error continuing intercepted request ProtocolError: Invalid InterceptionId.
    at /app/node_modules/chrome-remote-interface/lib/chrome.js:94:35
    at Chrome._handleMessage (/app/node_modules/chrome-remote-interface/lib/chrome.js:257:17)
    at WebSocket.<anonymous> (/app/node_modules/chrome-remote-interface/lib/chrome.js:235:22)
    at WebSocket.emit (node:events:519:28)
    at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:1068:20)
    at Receiver.emit (node:events:519:28)
    at Receiver.dataMessage (/app/node_modules/ws/lib/receiver.js:517:14)
    at /app/node_modules/ws/lib/receiver.js:468:23
    at /app/node_modules/ws/lib/permessage-deflate.js:308:9
    at /app/node_modules/ws/lib/permessage-deflate.js:391:7 {
  request: {
    method: 'Network.continueInterceptedRequest',
    params: { interceptionId: 'interception-job-2.1' },
    sessionId: undefined
  },
  response: { code: -32602, message: 'Invalid InterceptionId.' }
}

...and the server did not die. :)

While this prevents server crashes, I'm unsure if further changes are needed to address the root cause of the exception.

turicas added a commit to PythonicCafe/dokku-prerender that referenced this pull request Feb 24, 2024
There's an error if a bot tries to access, for example:
https://example.com/font.woff2
The only request the browser would do will be blocked and the client
will receive a 504 error.
@turicas
Copy link
Copy Markdown
Author

turicas commented Mar 4, 2024

Added a commit to fix another issue in this very same plugin: I got 504 errors when Googlebot was trying to access a .woff2 file. The whole request was blocked because we tried to do not load the file when another page uses it. With this fix, if the final URL is the same that should be blocked, then it's not blocked.

Sample log before the fix:

a.b.c.d - - [04/Mar/2024:16:11:32 -0300] "GET /https://example.net/font/fontname.woff2 HTTP/1.0" 504 197 "https://example.net/css/stylesheet.css" "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/121.0.6167.139 Safari/537.36"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant