#7552 closed Bugs (fixed)
win_iocp_io_service hangs due to a race condition
Reported by: | Owned by: | chris_kohlhoff | |
---|---|---|---|
Milestone: | To Be Determined | Component: | asio |
Version: | Boost 1.49.0 | Severity: | Regression |
Keywords: | asio windows hang | Cc: |
Description
The fix to #6321 introduced a bug that can cause the io_service to hang.
Example code (hangs eventually):
int main() { for (;;) { boost::asio::io_service ios; ios.post([]{ std::cout << '.'; }); boost::thread_group threads; for (size_t i = 0; i < 2; ++i) threads.create_thread([&]{ ios.run(); }); threads.join_all(); } }
Suppose that one of the threads read the posted operation, completed it and got to the work_finished function where it decremented outstanding_work to 0 and entered the stop function. Now the second thread starts. In the run function it sees that outstanding_work is 0 so it sets stopped to 1 and returns. Back in the first thread PostQueuedCompletionStatus(iocp_.handle, 0, 0, 0) isn't called since stopped is already 1. do_one returns 1 and is called again. GetQueuedCompletionStatus returns WAIT_TIMEOUT because the operation queue is empty, which causes the loop to continue to the next iteration ad infinitum.
Attachments (1)
Change History (4)
by , 10 years ago
Attachment: | asiohang.patch added |
---|
comment:1 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [82290]) Merge from trunk:
- Fix some 64-to-32-bit conversion warnings. Fixes #7459
- Fix typos in comments. Fixes #7761
- Fix error in example embedded in basic_socket::get_option's documentation. Fixes #7562
- Use long rather than int for SSL_CTX options, to match OpenSSL. Fixes #7209
- Use _snwprintf to address a compile error due to the changed swprintf signature in recent versions of MinGW. Fixes #7373
- Fix deadlock that can occur on Windows when shutting down a pool of io_service threads due to running out of work. Fixes #7552
- Enable noexcept qualifier for error categories. Fixes #7797
- Treat errors from accept as non-fatal. Fixes #7488
- Add a small block recycling optimisation.
- Version bump.
- Regenerate documentation.
comment:2 by , 9 years ago
Is this fixed in boost 1.53.0 ?
I've noticed there are changes in win_iocp_io_service.ipp but not in the area pointed in the proposed patch, namely inside do_one() to prevent the infinite loop.
Proposed fix for this bug.