Skip to content

Commit 8c29246

Browse files
authored
fix: use new host_api implementation for transactional lookups and inserts (#651)
Replaces the Simple Caches use of the direct caching host-calls with a cpp interface provided by host_api. Also adds a missing CacheHandle::transaction_lookup method and fixes the CacheHandle::lookup to use a non-transactional lookup (which was the bug that causes the SimpleCache API to freeze an application in version 3.2.0 - 3.3.3). Thank you @acfoltzer for hunting this down 🙇
1 parent 86ba2e7 commit 8c29246

File tree

8 files changed

+193
-263
lines changed

8 files changed

+193
-263
lines changed

integration-tests/js-compute/fixtures/cache-simple/bin/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,17 @@ async function simpleCacheEntryInterfaceTests() {
15611561
if (error) { return error }
15621562
return pass()
15631563
});
1564+
routes.set("/simple-cache/getOrSet/does-not-freeze-when-called-after-a-get", async () => {
1565+
let key = String(Math.random())
1566+
SimpleCache.get(key);
1567+
await SimpleCache.getOrSet(key, async () => {
1568+
return {
1569+
value: key,
1570+
ttl: 10
1571+
}
1572+
});
1573+
return pass()
1574+
});
15641575
}
15651576

15661577

integration-tests/js-compute/fixtures/cache-simple/tests.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,5 +838,15 @@
838838
"downstream_response": {
839839
"status": 200
840840
}
841+
},
842+
"GET /simple-cache/getOrSet/does-not-freeze-when-called-after-a-get": {
843+
"environments": ["c@e"],
844+
"downstream_request": {
845+
"method": "GET",
846+
"pathname": "/simple-cache/getOrSet/does-not-execute-the-set-method-when-key-is-in-cache"
847+
},
848+
"downstream_response": {
849+
"status": 200
850+
}
841851
}
842852
}

integration-tests/js-compute/test-harness.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export let FASTLY_SERVICE_VERSION;
1414
*/
1515
async function app(event) {
1616
let res = new Response('Internal Server Error', { status: 500 });
17+
const path = (new URL(event.request.url)).pathname
18+
console.log(`path: ${path}`)
1719
try {
18-
const path = (new URL(event.request.url)).pathname
19-
console.log(`path: ${path}`)
2020
FASTLY_SERVICE_VERSION = env('FASTLY_SERVICE_VERSION') || 'local'
2121
console.log(`FASTLY_SERVICE_VERSION: ${FASTLY_SERVICE_VERSION}`)
2222
if (routes.has(path)) {
@@ -26,7 +26,7 @@ async function app(event) {
2626
res = fail(`${path} endpoint does not exist`)
2727
}
2828
} catch (error) {
29-
res = fail(`The routeHandler threw an error: ${error.message || error}` + '\n' + error.stack)
29+
res = fail(`The routeHandler for ${path} threw an error: ${error.message || error}` + '\n' + error.stack)
3030
} finally {
3131
res.headers.set('fastly_service_version', FASTLY_SERVICE_VERSION);
3232
}

0 commit comments

Comments
 (0)