Open KamaniBhavin opened 5 months ago
The weird thing is that when I construct and new Request
object like below it works for ALL request methods.
export default {
fetch: async (request: Request, bindings: Bindings, executionContext: ExecutionContext) => {
const authorization = ....
// Create a new request object
const req = new Request(c.req.url, {
method: "POST", // Explicitly making it POST as GET throws error.
headers: { "authorization": authorization },
});
const s = await env.SERVICE_BINDINGS.doSomething(req);
},
};
Can you provide a complete worker that reproduces the problem? It's probably just a few more lines of code but it really helps us debug if we have a complete script we can just try running, rather than guess at the details.
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)
, whererequest
is a Cloudflare request object.In another script, bound to the aforementioned worker script, the method is used as follows:
When passing a request object using service bindings, the worker fails with different errors depending on the type of request.
Observed Behavior:
GET Request:
A GET or HEAD cannot have a body
.POST Request:
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:
doSomething
method.doSomething
method using service bindings.Additional Information:
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.
}