Skip to content

filesystem: refactor win32 watcher_impl to use absl mutex and fix buffer alignment - #46655

Open
citrus7 wants to merge 1 commit into
envoyproxy:mainfrom
citrus7:win32-watcher-absl-queue
Open

filesystem: refactor win32 watcher_impl to use absl mutex and fix buffer alignment#46655
citrus7 wants to merge 1 commit into
envoyproxy:mainfrom
citrus7:win32-watcher-absl-queue

Conversation

@citrus7

@citrus7 citrus7 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Additional Description:
Refactors the Win32 filesystem watcher (WatcherImpl):

  • Replaces <concurrent_queue.h> (concurrency::concurrent_queue) with a thread-safe ThreadSafeQueue using absl::Mutex. This eliminates duplicate symbol link conflicts between libc++ and MSVC libconcrt.lib.
  • Changes DirectoryWatch buffer type from std::vector<uint8_t> to std::vector<DWORD> ensuring 4-byte DWORD alignment required by ReadDirectoryChangesW and FILE_NOTIFY_INFORMATION.
  • Synchronizes access to DirectoryWatch::watches_ with an absl::Mutex.
  • Adds callAndLogOnError with exception handling and rate-limited logging.
  • Updates watcher_impl_test.cc to ensure file handles are cleanly closed before read events and flushes.

Risk Level: medium (Win32 filesystem watcher refactor)
Testing: bazel test //test/common/filesystem:watcher_impl_test
Docs Changes: n/a
Release Notes: Included under bug_fixes for Win32 watcher
Platform Specific Features: Windows

@citrus7

citrus7 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@yanavlasov

…fer alignment

Signed-off-by: Jonathan Wu <jtwu@google.com>
@citrus7
citrus7 force-pushed the win32-watcher-absl-queue branch from bf224e8 to 066d431 Compare August 11, 2026 20:33

@yanavlasov yanavlasov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need format to be fixed.

/wait

@@ -1,11 +1,10 @@
#pragma once

#include <concurrent_queue.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this header not available in Windows toolchain?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea using this forces the linker to pull in libconcrt.lib which can conflict with libc++, this change should make this library a lot more portable.

@tyxia tyxia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

callback_map_[fii_key] = std::make_unique<DirectoryWatch>();
callback_map_[fii_key]->dir_handle_ = dir_handle;
callback_map_[fii_key]->buffer_.resize(16384);
callback_map_[fii_key]->buffer_.resize(1024);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changed to 1024?

before this PR, it was resize(16384) on a vector<uint8_t> (16 KiB), now it is resize(1024) on a vector (4 KiB). Do we want to preserve capacity e.g., resize(4096)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadDirectoryChangesW requires the buffer to be DWORD-aligned (aligned to a 4-byte / 32-bit boundary). (https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-readdirectorychangesw)

Gemini seems to think that the old value was just a placeholder and incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants