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

Possible issue with cloudflare workers caused by a canceled promise #865

Closed
unlocomqx opened this issue May 14, 2024 · 2 comments
Closed

Comments

@unlocomqx
Copy link

unlocomqx commented May 14, 2024

Edit: I found the solution βœ…. I have to recreate the db client with each request.

Hi πŸ‘‹

I'm not entirely sure of the exact cause of this issue but I created a minimal repro. maybe someone can pinpoint the source of the issue.

Here's the repo
https://github.com/unlocomqx/cloudflare-error-1101

Here's the deploy to see the issue directly (The problem occurs once every two requests)
https://b8aef2ad.cloudflare-error-1101.pages.dev/db

CleanShot 2024-05-14 at 01 48 36@2x

The repo also has instructions to see the issue locally
CleanShot 2024-05-14 at 01 48 11@2x

Here's the error from wrangler

Error ✘ [ERROR] A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that the Promise cannot possibly ever resolve because all code and events related to the Promise's I/O context have already finished.

✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.

@unlocomqx
Copy link
Author

A more minimal repro with a better error message
https://github.com/unlocomqx/cloudflare-svelte-bug

✘ [ERROR] Error: Cannot perform I/O on behalf of a different request. I/O objects (such as streams, request/response bodies, and others) created in the context of one request handler cannot be accessed from a different request's handler. This is a limitation of Cloudflare Workers which allows us to improve overall performance. (I/O type: WritableStreamSink)

      at EventEmitter.write
  (file:///Users/USER/code/tests/cloudflare/my-svelte-app/node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/cf/polyfills.js:182:16)
      at nextWrite
  (file:///Users/USER/code/tests/cloudflare/my-svelte-app/node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/cf/src/connection.js:252:22)
      at null.<anonymous>
  (file:///Users/USER/code/tests/cloudflare/my-svelte-app/node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/cf/polyfills.js:224:7)
      at new Query
  (file:///Users/USER/code/tests/cloudflare/my-svelte-app/node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/cf/src/query.js:35:9)
      at sql2
  (file:///Users/USER/code/tests/cloudflare/my-svelte-app/node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/cf/src/index.js:113:11)
      at load
  (file:///Users/USER/code/tests/cloudflare/my-svelte-app/.svelte-kit/output/server/entries/pages/_page.server.js:7:23)
      at load_server_data
  (file:///Users/USER/code/tests/cloudflare/my-svelte-app/.svelte-kit/output/server/index.js:1008:42)
      at null.<anonymous>
  (file:///Users/USER/code/tests/cloudflare/my-svelte-app/.svelte-kit/output/server/index.js:2538:24)
  {
    query: 'SELECT * FROM users',
    parameters: [],
    args: [],
    types: []
  }

Deployed

@unlocomqx
Copy link
Author

unlocomqx commented May 14, 2024

I found the solution βœ…

pocketbase/pocketbase#2185 (comment)

I have to recreate the db client with each new request!

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

No branches or pull requests

1 participant