Setting cache path breaks extension use of local storage

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Setting cache path breaks extension use of local storage

Postby HarmlessDave » Wed Apr 14, 2021 5:05 pm

Windows 32-bit, CEF 87.1.12+g03f9336+chromium-87.0.4280.88

Our application needs to have shared cache storage and to persist local storage between application runs so we set the cache path. That worked until we tried to add a Chromium extension for accessibility provided by a partner. When it attempts to store a user login we get errors.

CEFClient produces the same errors if I add cache path settings to RunMain(), the errors don't happen if CefClient or our application does not set the path.

CEFClient code

Code: Select all
int RunMain(HINSTANCE hInstance, int nCmdShow) {
...
  CefString(&settings.cache_path) = "c:\\temp\\TestCache";
  CefString(&settings.root_cache_path) = "c:\\temp\\TestCache";

  // Create the main message loop object.
  scoped_ptr<MainMessageLoop> message_loop;


debug.log from both Debug and Release builds the warning appears just after the extension user login:

Code: Select all
[0414/143058.910:WARNING:settings_storage_quota_enforcer.cc(229)] Failed to get settings for quota:IO error: .../LOCK: File currently in use. (ChromeMethodBFE: 15::LockFile::2)
[0414/143100.929:INFO:CONSOLE(0)] "Unchecked runtime.lastError: IO error: .../LOCK: File currently in use. (ChromeMethodBFE: 15::LockFile::2)", source: chrome-extension://hdgegmlancchhhlkkddoiedlklgocffm/html/widget.html (0)
[0414/143105.342:INFO:CONSOLE(0)] "Unchecked runtime.lastError: IO error: .../LOCK: File currently in use. (ChromeMethodBFE: 15::LockFile::2)", source: https://www.google.com/?gws_rd=ssl (0)
[0414/143105.342:INFO:CONSOLE(0)] "Error handling response: TypeError: Cannot read property 'userInfo' of undefined


The c:\\temp\\TestCache folder was empty the first time I run CEFClient so it shouldn't be possible that Windows is hanging on to old locks of the LOCK file. It was created by this CEFClient session.

Am I making some mistake in setting the cache settings? The path is valid, the folder is empty, after running CEFClient all the normal sub-folders like Cache and files like LOCK are present.

If this isn't an obvious mistake, any suggestions for debugging it? I currently only have a minified version of the extension code but I might be able to get something readable.
HarmlessDave
Expert
 
Posts: 308
Joined: Fri Jul 11, 2014 2:02 pm

Re: Setting cache path breaks extension use of local storage

Postby magreenblatt » Wed Apr 14, 2021 6:43 pm

Are you trying to write the same cache directory from multiple simultaneously running applications? If so, that's not supported.
magreenblatt
Site Admin
 
Posts: 10858
Joined: Fri May 29, 2009 6:57 pm

Re: Setting cache path breaks extension use of local storage

Postby HarmlessDave » Wed Apr 14, 2021 7:00 pm

magreenblatt wrote:Are you trying to write the same cache directory from multiple simultaneously running applications? If so, that's not supported.


No, I can reproduce this using just one CEFClient with a single window open, with the extension loaded once and showing only its one window. Our application also enforces a single running instance.

Nothing else is using that folder in C:\\temp, and the folder is empty before opening CEFClient, then is filled up with the usual files after CEFClient runs.

I can toggle the errors on and off by uncommenting or commenting out the 2 settings cache path lines above, with no other changes to CEFClient.
HarmlessDave
Expert
 
Posts: 308
Joined: Fri Jul 11, 2014 2:02 pm

Re: Setting cache path breaks extension use of local storage

Postby magreenblatt » Wed Apr 14, 2021 8:47 pm

What does the extension that you're loading do? Does it work in Google Chrome?
magreenblatt
Site Admin
 
Posts: 10858
Joined: Fri May 29, 2009 6:57 pm

Re: Setting cache path breaks extension use of local storage

Postby HarmlessDave » Wed Apr 14, 2021 8:54 pm

magreenblatt wrote:What does the extension that you're loading do? Does it work in Google Chrome?


It's a custom screen reader extension for accessibility provided by a partner company, that was written last October to work with the more limited extension API that CEF supports. I'd have to get their permission first to disclose more details publicly.

It works without errors if I don't set the cache path. The lock errors only happen if the cache path is set.

They used CEFClient 84 for development when we were still on CEF 78, so we had to hold off on the integration work at the time. They didn't set the cache path so didn't see the lock errors. It's possible that they're doing something wrong with their use of local storage, but it's odd that it only happens with a custom cache path.

I was hoping to rule out errors on our part and any known issues in CEF before sending it back into their court.
HarmlessDave
Expert
 
Posts: 308
Joined: Fri Jul 11, 2014 2:02 pm

Re: Setting cache path breaks extension use of local storage

Postby HarmlessDave » Mon Apr 19, 2021 3:36 pm

Our partner provided me with a simplified extension and I've cut it down to a minimal 3 files:

CEFClient code to load the extension at startup from a sub-folder (..\tests\cefclient\browser\root_window_manager.cc)

Code: Select all
 void OnRequestContextInitialized(
      CefRefPtr<CefRequestContext> request_context) OVERRIDE {
    CEF_REQUIRE_UI_THREAD();

   // spawns floating window as browser id 2
   char ext_path[MAX_PATH];
   char* p;
   ::GetModuleFileNameA(NULL, ext_path, MAX_PATH);
   p = strrchr(ext_path, '\\');
   if (p != NULL)
   {
      p++;
      strcpy_s(p, 30, "Widget");
   }
   extension_util::LoadExtension(request_context, ext_path, this);






manifest.json
Code: Select all
{
  "manifest_version": 2,
  "name": "Test extension",
  "description": "Used in CEF based browsers.",
  "version": "840.0.0",
  "permissions": [
    "tabs",
    "storage",
    "<all_urls>",
    "http://*/*",
    "https://*/*"
  ],
  "browser_action": {
    "default_title": "Test extension",
    "default_popup": "../widget.html"
  }
}


widget.html
Code: Select all
<!doctype html>
<html>
<head>
    <title>Test Extension</title>
    <script src="widgetScript.js"></script>
</head>
<body>
Just click the LOGIN button to call storage.local.set() and trigger the LOCK error<br>
<input id="login-submit" type="submit" class="login-button" value="login" title="Login">
</body>
</html>


widgetScript.js
Code: Select all
'use strict';

document.addEventListener('DOMContentLoaded', function () {

   var login = document.getElementById("login-submit");
   login.addEventListener('click', function() {
      var data = {
         'myUser': {
            'username': 'abc',
            'displayName': 'Hello abc'
         }
      };

      chrome.storage.local.set({"myUserInfo": data}, function() {
         console.log('Attempted to store data');
      });
   });
});


This still shows the same behavior:
- CEFClient without a cache path set is fine. No errors, just the console info message when you click the LOGIN button.
- CEFClient with a cache path set gives a warning and error when the LOGIN button is clicked.

Code: Select all
[0419/133524.574:WARNING:settings_storage_quota_enforcer.cc(229)] Failed to get settings for quota:IO error: .../LOCK: File currently in use. (ChromeMethodBFE: 15::LockFile::2)
[0419/133526.607:INFO:CONSOLE(15)] "Attempted to store data", source: chrome-extension://eghdanedkmffncahgghjdcjdogoefahc/widgetScript.js (15)
[0419/133526.608:INFO:CONSOLE(0)] "Unchecked runtime.lastError: IO error: .../LOCK: File currently in use. (ChromeMethodBFE: 15::LockFile::2)", source: chrome-extension://eghdanedkmffncahgghjdcjdogoefahc/widget.html (0)


Does this look like a bug in CEF's implementation of the extension storage APIs? If so, any suggestion for proving that or should I just submit a bug report?
Last edited by HarmlessDave on Mon Apr 19, 2021 5:01 pm, edited 1 time in total.
HarmlessDave
Expert
 
Posts: 308
Joined: Fri Jul 11, 2014 2:02 pm

Re: Setting cache path breaks extension use of local storage

Postby magreenblatt » Mon Apr 19, 2021 4:59 pm

It could be a bug in the CEF implementation. However, official extension support with the Alloy runtime is currently limited to what's required by the PDF viewer. A PR may be accepted if you're able to fix the problem yourself.
magreenblatt
Site Admin
 
Posts: 10858
Joined: Fri May 29, 2009 6:57 pm

Re: Setting cache path breaks extension use of local storage

Postby ndesktop » Tue Apr 20, 2021 12:45 am

I have tested with my custom build of 4389 and is working for me, either with direct load of extension from OnRequestContextInitialized, or with --load-extension. A file LocalPrefs.json was created with this content:
Code: Select all
{"os_crypt":{"encrypted_key":"RFBBUEkBAAAA0Iyd3w...."},"profile_network_context_service":{"http_cache_finch_experiment_groups":"None None None"}}


(I think root_cache_path and cache_path should probably not be the same, most likely root_cache_path would contain various cache_path for different users, sessions etc. But I might get this one wrong).

Also, I would point out these details might worth checking:
- the error
Code: Select all
[0419/133524.574:WARNING:settings_storage_quota_enforcer.cc(229)] Failed to get settings for quota:IO error: .../LOCK: File currently in use. (ChromeMethodBFE: 15::LockFile::2)

is probably coming from SettingsStorageQuotaEnforcer, specifically from LazyCalculateUsage() function
Code: Select all
if (!maybe_settings.status().ok()) {
    LOG(WARNING) << "Failed to get settings for quota:"
                 << maybe_settings.status().message;
    return;
  }

- error 2 is strange, but I think if it really is 2, it is probably LockFileEx failing with ERROR_SHARING_VIOLATION which gets translated by OSErrorToFileError from ERROR_SHARING_VIOLATION to FILE_ERROR_IN_USE. However, the latter is -2, not 2.
- I would recheck if the directory really exists
- it is possible that an AV driver to intercept the file/directory activity before the call gets back to user mode in cefclient, so it might be locked by an upper component (ProcMon or a ProcExp runas admin search for C:\temp\TestCache might indicate another process reading)
- it might be explorer itself or one of its shell extensions.
ndesktop
Master
 
Posts: 538
Joined: Thu Dec 03, 2015 10:10 am

Re: Setting cache path breaks extension use of local storage

Postby HarmlessDave » Tue Apr 20, 2021 12:51 pm

ndesktop wrote:I have tested with my custom build of 4389 and is working for me, either with direct load of extension from OnRequestContextInitialized, or with --load-extension.


Thanks for testing this and for trying to narrow down the error.

How are you setting a cache path? Loading the extension works for us in CEF 87 / branch 4280 until we set a specific cache path.


- I would recheck if the directory really exists


It's not that. A couple of us have tried multiple paths on two different PCs. The original path I used was in users > appdata > local but I also tried creating c:\\temp\\TestCache. The folder exists and all the usual files get created there including LOCK.

(I think root_cache_path and cache_path should probably not be the same, most likely root_cache_path would contain various cache_path for different users, sessions etc. But I might get this one wrong).


The .h file claims it's OK for them to be the same, but we also get the error from setting just the (non-root) cache path, and from using the command line `D:\CEFTest\Debug_GN_x86>cefclient --load-extension=c:\widget\dist\widget --cache-path="d:\CEFTest\TestCache"`

- it is possible that an AV driver to intercept the file/directory activity before the call gets back to user mode in cefclient, so it might be locked by an upper component (ProcMon or a ProcExp runas admin search for C:\temp\TestCache might indicate another process reading)
- it might be explorer itself or one of its shell extensions.


These are possible, though I use Microsoft's Defender which is less likely to mess with file access than others, and we have no problems with JavaScript code using local storage on HTML test web pages, it's the extension use of storage that has the problem.

It's possible that something was fixed between CEF 87 and 89, so we can try downloading an 89 binary and seeing if it still has the problem.
HarmlessDave
Expert
 
Posts: 308
Joined: Fri Jul 11, 2014 2:02 pm

Re: Setting cache path breaks extension use of local storage

Postby ndesktop » Tue Apr 20, 2021 1:06 pm

HarmlessDave wrote:Thanks for testing this and for trying to narrow down the error.
How are you setting a cache path?


I pasted your code samples from the narrowing example into cefclient, setting root_cache_path and cache_path immediately after CefSettings declaration, and the extension loading code at the beginning of OnRequestContextInitialized.

However, I did *not* tested with stock CEF distribution, having a (heavily) modified CEF branch.
Currently I do have a 90.4430 build in progress and I hope to find time this week to try cefclient with these minimal modifications.
I'll get back as soon as I have a result.
ndesktop
Master
 
Posts: 538
Joined: Thu Dec 03, 2015 10:10 am

Next

Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 20 guests