You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
got hangs on revalidated cached response. That is, a response gets revalidated because max-age is reached, while the cached body is still valid (e.g. matching etag).
Actually, it seems like there's already a test, currently marked as failing, exactly covering this case:
While that allows the promise to be resolved, it caused other test cases to fail.
I'm afraid I'm too unfamiliar with the code base to come up with a suitable solution, but happy to help if pointed in the right direction.
Actual behavior
Hangs indefinitely, respectively crashes the process if used in a top-level await.
Expected behavior
Should return revalidated cached response
Code to reproduce
importgotfrom'got';classSimpleCache{cached;get(){returnthis.cached;}set(_,value){constentry=JSON.parse(value);// To force immediate revalidationentry.value.cachePolicy.rescc['max-age']='0';this.cached=JSON.stringify(entry);}}constcache=newSimpleCache();// npm registry is a good showcaseconsturl='https://registry.npmjs.org/got';letresponse=awaitgot(url,{ cache });console.log(response.isFromCache);response=awaitgot(url,{ cache });console.log(response.isFromCache);
Run with:
node test.js;echo$?
Because it's a top-level await, Node.js correctly detects that the promise will never get resolved (exit code 13):
false
13
Checklist
I have read the documentation.
I have tried my code with the latest version of Node.js and Got.
The text was updated successfully, but these errors were encountered:
Describe the bug
got
hangs on revalidated cached response. That is, a response gets revalidated becausemax-age
is reached, while the cached body is still valid (e.g. matchingetag
).Actually, it seems like there's already a test, currently marked as failing, exactly covering this case:
got/test/cache.ts
Line 476 in 3822412
I've tracked the issue down to
got/source/core/index.ts
Line 879 in 3822412
which is called in
got/source/core/index.ts
Line 842 in 3822412
I think the issue here is that the response (coming from cache, thus no actual response) never finishes, so
getStreamAsBuffer
waits indefinitely.At first, I thought a fix could be as simple as
While that allows the promise to be resolved, it caused other test cases to fail.
I'm afraid I'm too unfamiliar with the code base to come up with a suitable solution, but happy to help if pointed in the right direction.
Actual behavior
Hangs indefinitely, respectively crashes the process if used in a top-level await.
Expected behavior
Should return revalidated cached response
Code to reproduce
Run with:
Because it's a top-level await, Node.js correctly detects that the promise will never get resolved (exit code 13):
Checklist
The text was updated successfully, but these errors were encountered: