Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unhandled exception on blockResources #778

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

turicas
Copy link

@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
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.

None yet

1 participant