cloudflare / cloudflare/workerd
🐛 BUG: RPC Entrypoint Misbehaves with Request Object
- Dominant language
- C++
- Stars
- 8.7k
- Forks
- 739
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 174
Description
### Which Cloudflare product(s) does this pertain to?
Workers Runtime
### What version(s) of the tool(s) are you using?
wrangler 3.57.2
### What version of Node are you using?
v18.18.2
### What operating system and version are you using?
Mac Sonoma 14.2.1
### Describe the Bug
###
**Issue Description:**
I am experiencing issues with a Cloudflare worker that uses an RPC entrypoint. The worker script includes a method `doSomething(request: Request)`, where `request` is a Cloudflare request object.
```typescript
export class RpcEntrypoint extends WorkerEntrypoint {
async doSomething(request: Request) {
return await fn(this.env, request);
}
}
```
In another script, bound to the aforementioned worker script, the method is used as follows:
```typescript
export default {
fetch: async (request: Request, bindings: Bindings, executionContext: ExecutionContext) => {
const s = await env.SERVICE_BINDINGS.doSomething(request);
},
};
```
When passing a request object using service bindings, the worker fails with different errors depending on the type of request.
**Observed Behavior:**
1. **GET Request:**
- Error: `A GET or HEAD cannot have a body`.
2. **POST Request:**
- Error: `A promise rejection was handled asynchronously. This warning occurs when attaching a catch handler to a promise after it rejected. (rejection cloudflare/workers-sdk#1) TypeError: The ReadableStream has been locked to a reader.`
**Expected Behavior:**
The `doSomething` method should handle both GET and POST requests without causing errors.
**Steps to Reproduce:**
1. Set up a Cloudflare worker with the `doSomething` method.
2. Bind another script to the worker.
3. Pass a request object to the `doSomething` method using service bindings.
4. Observe the errors for GET and POST requests.
**Additional Information:**
- Cloudflare Workers version: [wrangler 3.57.2]
- Service Bindings configuration:
```
services = [
{ binding = "SERVICE_BINDINGS", service = "service", entrypoint = "RpcEntrypoint" },
]
```
Any insights or solutions to handle these request types correctly within the worker would be greatly appreciated.
### Please provide a link to a minimal reproduction
_No response_
### Please provide any relevant error logs
A promise rejection was handled asynchronously. This warning occurs when attaching a catch handler to a promise after it rejected. (rejection cloudflare/workers-sdk#1)
TypeError: The ReadableStream has been locked to a reader.
at JsRpcProperty. ()
at file:///Users/bhavinkamani/IdeaProjects/crm-integrations/.wrangler/tmp/dev-kdLmfa/index.js:10790:44
at dispatch (file:///Users/bhavinkamani/IdeaProjects/crm-integrations/.wrangler/tmp/dev-kdLmfa/index.js:314:23)
at file:///Users/bhavinkamani/IdeaProjects/crm-integrations/.wrangler/tmp/dev-kdLmfa/index.js:315:20
at file:///Users/bhavinkamani/IdeaProjects/crm-integrations/.wrangler/tmp/dev-kdLmfa/index.js:1706:11
at async dispatch (file:///Users/bhavinkamani/IdeaProjects/crm-integrations/.wrangler/tmp/dev-kdLmfa/index.js:314:17)
at async file:///Users/bhavinkamani/IdeaProjects/crm-integrations/.wrangler/tmp/dev-kdLmfa/index.js:1706:5
at async dispatch (file:///Users/bhavinkamani/IdeaProjects/crm-integrations/.wrangler/tmp/dev-kdLmfa/index.js:314:17)
at async file:///Users/bhavinkamani/IdeaProjects/crm-integrations/.wrangler/tmp/dev-kdLmfa/index.js:950:25
at async drainBody (file:///Users/bhavinkamani/IdeaProjects/crm-integrations/.wrangler/tmp/dev-kdLmfa/index.js:11029:12) {
stack: TypeError: The ReadableStream has been locked to a…tions/.wrangler/tmp/dev-kdLmfa/index.js:11029:12),
message: The ReadableStream has been locked to a reader.
}
Contributor guide
Research direction
Start with the RPC entrypoint and the JsRpcProperty call path shown in the error trace, then reproduce the service-binding call for both GET and POST requests. Done means a Request object can be passed to doSomething without the GET body or locked ReadableStream errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100