Csaba Varga
Csaba Varga
CDCloudflare Developers
Created by Csaba Varga on 7/26/2024 in #workers-help
Deadlock in cache.put() - platform issue or am I doing something wrong?
Looks like that linked issue is exactly the same thing I ran into, so I'm watching it
11 replies
CDCloudflare Developers
Created by Csaba Varga on 7/26/2024 in #workers-help
Deadlock in cache.put() - platform issue or am I doing something wrong?
Yes, in our production code, I worked around the issue by collecting responses in an array and calling cache.put on them after the rewriter was done, but I assume it should work in parallel as well.
11 replies
CDCloudflare Developers
Created by Csaba Varga on 7/26/2024 in #workers-help
Deadlock in cache.put() - platform issue or am I doing something wrong?
Hi! Thank you for taking a look at this
11 replies
CDCloudflare Developers
Created by Csaba Varga on 7/26/2024 in #workers-help
Deadlock in cache.put() - platform issue or am I doing something wrong?
This variant is also interesting:
export default {
async fetch(request, env, ctx) {
let myResponse = await fetch('http://example.com/');
myResponse = new HTMLRewriter()
.on('h1', {
async element(e) {
const dummyResponse = new Response('foo');
caches.default.put(new Request('http://example.com/dummy'), dummyResponse.clone());
console.log('about to call text()');
const text = await dummyResponse.text();
console.log(`text() == ${text}`);
e.setInnerContent('Rewritten');
}
})
.transform(myResponse);
caches.default.put(request, myResponse.clone());
return myResponse;
},
};
export default {
async fetch(request, env, ctx) {
let myResponse = await fetch('http://example.com/');
myResponse = new HTMLRewriter()
.on('h1', {
async element(e) {
const dummyResponse = new Response('foo');
caches.default.put(new Request('http://example.com/dummy'), dummyResponse.clone());
console.log('about to call text()');
const text = await dummyResponse.text();
console.log(`text() == ${text}`);
e.setInnerContent('Rewritten');
}
})
.transform(myResponse);
caches.default.put(request, myResponse.clone());
return myResponse;
},
};
Here, I'm not waiting for the put() call to finish, but its presence still interferes with consuming the response. The message "about to call text()" appears on the console, but nothing else is logged, so the code is waiting forever for the body of the dummy response. (This is despite the response body being already in memory, and trivially short.) It's definitely weird that even after cloning the response, the two copies can block each other.
11 replies