-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Runtime Type Error in Cache-Parser Where Header Token Contains no , #301
Comments
cc @baronfel |
Hey @nagilson, can you setup a small reproducible example or paste here a |
Thank you so much for your very fast reply. May you help me gather that information for you? The header seems to be generated from Axios-Cache-Interceptor, so I'm not sure where it's generated, or what it is, to be honest. Is there something we could type in the developer browser console to access that information? The web request this is for is one for: https://dot.net/v1/dotnet-install.sh It does not always happen, in fact I have not been able to get it to happen. So giving a clear repro is also challenging. The real repo is downloading VS Code and running .NET, and having one of the very small weird scenarios that seems to cause this web request to fail. |
Source: const tokens = headerStr.toLowerCase().replace(/\s+/g, '').split(',');
for (const token of tokens) {
const split = token.split('=', 2) as [string, string];
headers[split[0]] = split[1] ?? true;
} Transpiled: var a = {},
r = e.toLowerCase().replace(/\s+/g, '').split(',');
for (var t in r) {
var s,
n = r[t].split('=', 2);
a[n[0]] = null == (s = n[1]) || s;
}
Normally, Am I missing something or this seems to be a bug in the js runtime? |
@arthurfiorette The more I am looking at the code, I am not seeing what value would cause this to happen yet either. One sec... |
Maybe |
Hm, that's a good theory. I checked and it looks like it's coming from What I am suspicious about is that my minified code is identical to yours, and despite the fact that the callstack aligns with the Based on the Javascript spec, this should not be possible. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#:~:text=Note%3A%20%22%22.split(%22%22)%20is%20therefore%20the%20only%20way%20to%20produce%20an%20empty%20array%20when%20a%20string%20is%20passed%20as%20separator%20and%20limit%20is%20not%200. Split would never return an empty array, and you loop for token in tokens anyway. Token would have to be a non string type, but I dont see in the spec how that is possible with string. |
I'm going to double check with our customer to see if their string split method has been modified. (Note this has happened more than a few times, so I would not resolve it to a bit flip...) |
Another thought: Typescript checks are only at compile time. Does any of your code edit variables at runtime in places it would not do so at compile time? |
I actually have no clue on how to solve this issue... I build the project in my machine and the output seems to have changed, probably because the bundler have been updated since the latest I could try to release a new version with this different bundle and see if this error stops... |
Everything gets executed the same way it's written... |
Hey @nagilson any updates? |
@arthurfiorette Apologies, I was on vacation. The thing I can confirm is that the string split method was not modified. I don't have any further insights at the moment. So I would appreciate you giving it a go with the bundler to see if that fixes the issue. Theoretically there could also be some sort of 'guard' in place in the code even though we don't think its possible to encounter this situation, but that's not ideal coding of course. If it could be changed to collect more information for when it does happen for the next report we get, that'd be helpful (IDK if this has a log system.) Thanks for your continued investment in my issue. |
Just released v1.2.5. Let's see if it fixes this weird problem :/ |
Hey @nagilson, axios-cache-interceptor v1.5.3 was released with cache-parser v1.2.5. Let's wait some time to see if it fixes this weird issue :/ |
Thanks! Ill get the update in our next release and see if it fixes it :) |
What happened?
This code: https://github.com/arthurfiorette/tinylibs/blob/main/packages/cache-parser/src/util.ts#L18 , which this library seems to depend on, is failing at runtime for us in a rare number of cases.
(I was very relieved to see you manage both libraries, so thank you for the work you do :). )
My very quick glance is the problem is the code seems to rely on the fact that , is in the header of the string that is passed to it. I dont think that assumption can always hold true, so sometimes the token ends up being null or a type other than string, so when .split is called on it, there becomes an uncaught runtime error. The split on line 22 is the culprit.
I don't know much more of the context of the code here and there might be some other reason, but that is my suspicion.
Example is dotnet/vscode-dotnet-runtime#1734.
I don't have a repro, this info is garnered from customers.
It is causing some issues for us over in VS Code land and it is one of our highest causes of failure, causing roughly .01% out of several million customers to fail, with a high report rate on mac os sonoma silicon m1.
axios-cache-interceptor version
^1.0.1
Node / Browser Version
16
Axios Version
^1.3.4
What storage is being used
Memory Storage
Relevant debugging log output
The text was updated successfully, but these errors were encountered: