Skip to content

File service: revisit leaking file handles from error cases causing some of our tests to fail #114024

Closed

Description

Noticed today on Windows in https://github.com/microsoft/vscode/runs/1666194411#step:11:7666

  6398 passing (2m)
  19 pending
  1 failing

  1) Disk File Service
       "after each" hook for "readFile - FILE_EXCEEDS_MEMORY_LIMIT - streamed":
     Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

Three observations:

  • a failure in a teardown does not benefit from mocha.retry
  • there is filesystem contention in this rather late fs test. very many tests do not await unlinking and the test suite also does not use graceful-fs.
  • some tests (e.g. BackupTracker) cause continued FS writing to their fixture folder even after the test has finished, which would trip a simple rimraf with ENOTEMPTY errors.

I am working on a PR to improve reliability in this space.

fyi Benjamin Pasero (@bpasero)

Activity

  1. bpasero commented on Jan 8, 2021

    @bpasero
    Contributor

    Let's see how the latest changes perform.

  2. alexdima commented on Jan 11, 2021

    @alexdima
    MemberAuthor

    I haven't seen any test failures in this area in over 100 builds today. I would optimistically close this.

  3. bpasero commented on Jan 13, 2021

    @bpasero
    Contributor
    1) Disk File Service
           "after each" hook for "readFile - FILE_EXCEEDS_MEMORY_LIMIT - streamed":
         Error: ENOTEMPTY: directory not empty, rmdir 'C:\Users\VSSADM~1\AppData\Local\Temp\vsctests\diskfileservice\2bb4054d-19d3-4dc3-8c45-ca6172234760'
    

    https://dev.azure.com/monacotools/Monaco/_build/results?buildId=100269&view=logs&j=306b2268-2a17-5e97-ab97-f41a26dc5206&t=99b4f36c-57e7-52a9-d2fb-83a564c876a6&l=7673

  4. alexdima commented on Jan 14, 2021

    @alexdima
    MemberAuthor

    I've enabled fs logging for that test. The test does the following fs calls, which might be incorrect:

    calling open: TESTDIR\index.html,r
    calling lstat: TESTDIR\index.html
    calling read: 3
    calling open: TESTDIR\index.html,r
    calling lstat: TESTDIR\index.html
    calling read: 4
    calling close: 3
    calling close: 4
    

    I find it weird that the fd 3 is closed only after the second open call. It looks like the first await does not actually await for the fd to be closed:

    		await doTestFileExceedsMemoryLimit();
    
    		// Also test when the stat size is wrong
    		fileProvider.setSmallStatSize(true);
    		return doTestFileExceedsMemoryLimit();
    
  5. alexdima commented on Jan 14, 2021

    @alexdima
    MemberAuthor

    The problematic code is here:

    const [fileStat, fileStream] = await Promise.all([statPromise, fileStreamPromise]);

    In that particular test, the statPromise resolves with an error and I believe Promise.all does not really wait for fileStreamPromise. So it looks like in this particular case readFile resolves with an error before having cleaned up the fd fileStreamPromise used.

    In other words:

    try {
    	await service.readFile(resource, { limits: { memory: 10 } });
    } catch (err) {
    	// ---> there is still an open fd to the resource here which is incorrect
    	error = err;
    }
  6. bpasero commented on Jan 14, 2021

    @bpasero
    Contributor

    Alexandru Dima (@alexdima) thanks, this is a nice catch. I think there is 2 questions here:

    • does it impact normal VSCode usage
    • is there a fix possible for unit tests

    We actually have a way of cancelling a file open when an error occurs here:

    const statPromise = this.validateReadFile(resource, options).then(stat => stat, error => {
    cancellableSource.cancel();
    throw error;
    });

    This would not help for the unit tests because it all happens async, but at least for normal usage the stream should not be consumed in case we error like that because of file limits.

    Digging a bit deeper, it seems the token is respected all the way to here where we open the file handle:

    const handle = await provider.open(resource, { create: false });

    However the fact that we seem to throwIfCancelled right after without closing that file descriptor seems fishy to me and sounds like a bug.

    const handle = await provider.open(resource, { create: false });
    // Check for cancellation
    throwIfCancelled(token);

    I will look into this closer tomorrow.

  7. added
    bug
    file-io
    on Jan 14, 2021
  8. changed the title [-]Flaky test: Disk File Service[/-] [+]File service: revisit leaking file handles from error cases causing some of our tests to fail[/+] on Jan 14, 2021
  9. added
    unreleased
    insiders-released
    and removed
    unreleased
    on Jan 19, 2021
  10. removed
    bug
    on Jan 29, 2021
  11. locked and limited conversation to collaborators on Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

file-ioinsiders-releasedunit-test-failure

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions