vscode: VS Code randomly does a save before our extension returns willSaveWaitUntil results in < 500ms

Does this issue occur when all extensions are disabled?: Yes

Version: 1.75.0-insider (user setup) Commit: a0562ccdb202a29ac35da81c2b5482e517158f32 Date: 2023-01-18T08:54:05.566Z Electron: 19.1.9 Chromium: 102.0.5005.194 Node.js: 16.14.2 V8: 10.2.154.23-electron.0 OS: Windows_NT x64 10.0.22621 Sandboxed: Yes

Steps to Reproduce:

  1. Install the C/C++ extension, 1.14.0 (pre-release) (1.13.9 should work too). We use the willSaveWaitUntil registered via the LSP. I added timing logging at https://github.com/microsoft/vscode-cpptools/blob/seanmcm/willSaveWaitUntilLogging/Extension/src/LanguageServer/protocolFilter.ts#L100 to verify we return results in < 1.5 seconds., but our existing logging (setting "C_Cpp.loggingLevel": "Debug") already has timing logging (although it’s at a different spot so it might not be as accurate).
  2. Open an empty folder.
  3. Create a test.cpp file.
  4. Paste the code below multiple times – the amount of pasting you need may depend on the speed of your computer, i.e. the bug appears to only repro when the file is big enough, e.g. 7-14k lines. This is an artificial repro, but the initial repro was with our closed source code.
#include <algorithm>
#include <cstdlib>
#include <numeric>
#include <atomic>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfenv>
#include <cfloat>
#include <cinttypes>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cuchar>
#include <cwchar>
#include <cwctype>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <cassert>
#include <exception>
#include <stdexcept>
#include <system_error>
#include <any>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <memory>
#include <optional>
#include <ratio>
#include <scoped_allocator>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <utility>
#include <variant>
#include <cinttypes>
#include <cstdio>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <sstream>
#include <streambuf>
#include <iterator>
#include <cfloat>
#include <climits>
#include <codecvt>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <initializer_list>
#include <limits>
#include <new>
#include <typeinfo>
#include <clocale>
#include <codecvt>
#include <locale>
#include <cfenv>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <random>
#include <ratio>
#include <valarray>
#include <memory>
#include <new>
#include <scoped_allocator>
#include <atomic>
#include <condition_variable>
#include <future>
#include <mutex>
#include <shared_mutex>
#include <thread>
#include <regex>
#include <charconv>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cuchar>
#include <cwchar>
#include <cwctype>
#include <regex>
#include <string>
#include <string_view>
#include <chrono>
#include <ctime>
#include <stop_token>
#include <memory_resource>
#include <compare>
#include <version>
#include <bit>
#include <numbers>
#include <execution>
#include <bit>
#include <span>
#include <concepts>
#include <ranges>
#include <latch>
#include <barrier>
#include <cvt/wbuffer>
#include <cvt/wstring>
#include <coroutine>
  1. Add this to your folder’s settings.json:
    "C_Cpp.codeAnalysis.clangTidy.checks.enabled": [
        "*"
    ],
  1. Repro is to right-click a C++ file and select Run Code Analysis on Active File and then make an edit and save.

Bug: Our LSP server returns results in <500ms as indicated: see this logging screenshot: image

But VS Code does a save before that and fails because our extension has the file in use. The extension host does not give the any errors regarding “onWillSaveTextDocument” because we correctly return results in time. See this screenshot:

image

That logging screenshot above is not checked into the main product but is from the modified branch, but if you set C_Cpp.loggingLevel to “Debug” the “C/C++” logging pane will show timing info like: willSaveWaitUntil: 421ms.

The “Failed to save” appears “instantly” without the expected 1.5 second delay (in addition to the logging tell me).

From what I (and others on our team) can tell the behavior seems completely random (repro probability seems to become 100% with a big enough file).

Let me know how I can get more logging, diagnostic, or repros and/or debug the issue, etc.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 30 (29 by maintainers)

Commits related to this issue

Most upvoted comments

@bpasero Thanks for clarifying. @sean-mcmanus Given those insights can you please analyse what save flows your extension might be triggering here?