Repository navigation
Conversation
Timeout reclamation can close a semaphore handle after a waiter drops the queue mutex but before it enters the kernel wait. Pin locally used semaphores until waiting completes, including cancellation and errors. Initialize the retirement flag and make the resolved query pointer atomic. Its accesses can remain relaxed because the dispatcher already publishes initialization through its release/acquire pair. Cover active, cancelled, and failed waits with native handle-lifetime regressions. Bound intercepted waits so lost notifications fail a case instead of hanging the test executable.
f8339f0 to
2eb4dd4
Compare
|
|
||
| static boost::atomic< is_semaphore_zero_count_t > is_semaphore_zero_count; | ||
| static nt_query_semaphore_t nt_query_semaphore; | ||
| static boost::atomic< nt_query_semaphore_t > nt_query_semaphore; |
There was a problem hiding this comment.
I don't think this is needed. The variable is used when is_semaphore_zero_count is is_semaphore_zero_count_nt_query_semaphore. It is set by is_semaphore_zero_count_init before the store to is_semaphore_zero_count with release semantics and loaded by is_semaphore_zero_count_nt_query_semaphore, which is called through the pointer loaded from is_semaphore_zero_count with acquire semantics. Concurrent stores to it in is_semaphore_zero_count_init are not an issue since the same value is stored.
| #undef BOOST_LOG_WINDOWS_IPC_SYNC_WRAPPERS_HPP_INCLUDED_ | ||
| #undef BOOST_LOG_WINDOWS_AUTO_HANDLE_HPP_INCLUDED_ | ||
| #define interprocess_event test_interprocess_event | ||
| #define interprocess_semaphore test_interprocess_semaphore | ||
| #define interprocess_mutex test_interprocess_mutex | ||
| #define interprocess_condition_variable test_interprocess_condition_variable | ||
| #define tick_count_clock test_tick_count_clock | ||
| #define auto_handle test_auto_handle | ||
| #define g_hex_char_table test_hex_char_table | ||
| #define GetTickCount64 test_GetTickCount64 | ||
| #define GetTickCount test_GetTickCount | ||
| #define CloseHandle test_CloseHandle | ||
| #define WaitForMultipleObjects test_WaitForMultipleObjects | ||
| #include "../../src/windows/ipc_sync_wrappers.cpp" | ||
| #undef WaitForMultipleObjects | ||
| #undef CloseHandle | ||
| #undef GetTickCount | ||
| #undef GetTickCount64 | ||
| #undef g_hex_char_table | ||
| #undef auto_handle | ||
| #undef tick_count_clock | ||
| #undef interprocess_condition_variable | ||
| #undef interprocess_mutex | ||
| #undef interprocess_semaphore | ||
| #undef interprocess_event |
There was a problem hiding this comment.
Sorry, but I don't find this acceptable. The test must verify the component as it is compiled in the library, with no source modification or relying on implementation details. If this is not possible (even sometimes, if the problem is not deterministic) then that feature is untestable and no test is acceptable.
| if [ path.basename $(file) ] = "util_ipc_windows_sync.cpp" | ||
| { | ||
| all_rules += [ run $(file) : : : <include>../src ] ; | ||
| } | ||
| else | ||
| { | ||
| all_rules += [ run $(file) ] ; | ||
| } |
There was a problem hiding this comment.
This should not be needed. The test already checks if the target is Windows.
|
Thanks, I've committed my own fix. |
Windows IPC queue synchronization can close a semaphore handle while a live thread still needs it.
A waiter records the handle, releases the queue mutex, and then enters the Windows wait call. If the thread is delayed between unlocking and waiting, another thread can retire the semaphore after its cleanup timeout. The original waiter can then use an invalid handle, or one that Windows has reused for a different object.
Track local waiters and keep their semaphore handles alive until the waiting path finishes. Release those references on success, cancellation, and exceptions so unused semaphores can still be reclaimed.
Also initialize the semaphore-retirement flag and make access to the lazily resolved semaphore-query function pointer atomic. Its atomic accesses can remain relaxed because the existing dispatcher publishes the pointer through its release/acquire pair; atomic access is still needed because initializers can run concurrently.
Add three tests in
test/run/util_ipc_windows_sync.cpp. They exercise the actual synchronization implementation with real Windows handles while controlling wait scheduling and elapsed time. The test wrapper caps native waits at five seconds and reports a timeout as a failure of the current case, allowing the remaining cases to run.Against the original code, the lifetime test detects that cleanup closes the handle before the waiting path finishes. With the fix, the handle remains open. Two further tests verify that cancelled and failed waits release their references and allow later cleanup.
All three tests pass on native Windows with MSYS2 GCC 16.2 and C++11. A temporary lost-notification test variant fails through the five-second timeout and then runs both remaining cases successfully.