Skip to content

Commit d03c2e7

Browse files
committed
Fix error reporting on IOCP out of resources.
Here is my understanding of the history of this patch. The patch that was applied to MongoDB's old vendored ASIO is [0006-MONGO-Fix-IOCP-out-of-resource-handling.patch][1]. That patch is a solution to an [outstanding issue][2] in upstream ASIO, both then and now. The reason we applied the patch was because we thought that is might be the solution to `BF-9006`. So, [SERVER-36885][3] was created to patch ASIO. But in `SERVER-36885`, its author says that likely the BF wasn't caused by this ASIO issue, but instead was fixed by [SERVER-38789][4]. So, these changes probably address a genuine issue in ASIO, but possibly not one that MongoDB has ever encountered. [1]: https://github.com/mongodb/mongo/blob/4c38808c10021549e34e59b696e89b6541fae4c4/src/third_party/asio-master/patches/0006-MONGO-Fix-IOCP-out-of-resource-handling.patch [2]: chriskohlhoff#312 [3]: https://jira.mongodb.org/browse/SERVER-36885 [4]: https://jira.mongodb.org/browse/SERVER-38789
1 parent caca4fa commit d03c2e7

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

asio/include/asio/detail/impl/win_iocp_io_context.ipp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void win_iocp_io_context::post_deferred_completion(win_iocp_operation* op)
308308
op->ready_ = 1;
309309

310310
// Enqueue the operation on the I/O completion port.
311-
if (!::PostQueuedCompletionStatus(iocp_.handle, 0, 0, op))
311+
if (!::PostQueuedCompletionStatus(iocp_.handle, 0, op->completionKey(), op))
312312
{
313313
// Out of resources. Put on completed queue instead.
314314
mutex::scoped_lock lock(dispatch_mutex_);
@@ -328,7 +328,7 @@ void win_iocp_io_context::post_deferred_completions(
328328
op->ready_ = 1;
329329

330330
// Enqueue the operation on the I/O completion port.
331-
if (!::PostQueuedCompletionStatus(iocp_.handle, 0, 0, op))
331+
if (!::PostQueuedCompletionStatus(iocp_.handle, 0, op->completionKey(), op))
332332
{
333333
// Out of resources. Put on completed queue instead.
334334
mutex::scoped_lock lock(dispatch_mutex_);
@@ -355,8 +355,9 @@ void win_iocp_io_context::on_pending(win_iocp_operation* op)
355355
if (::InterlockedCompareExchange(&op->ready_, 1, 0) == 1)
356356
{
357357
// Enqueue the operation on the I/O completion port.
358+
op->completionKey() = overlapped_contains_result;
358359
if (!::PostQueuedCompletionStatus(iocp_.handle,
359-
0, overlapped_contains_result, op))
360+
0, op->completionKey(), op))
360361
{
361362
// Out of resources. Put on completed queue instead.
362363
mutex::scoped_lock lock(dispatch_mutex_);
@@ -379,8 +380,9 @@ void win_iocp_io_context::on_completion(win_iocp_operation* op,
379380
op->OffsetHigh = bytes_transferred;
380381

381382
// Enqueue the operation on the I/O completion port.
383+
op->completionKey() = overlapped_contains_result;
382384
if (!::PostQueuedCompletionStatus(iocp_.handle,
383-
0, overlapped_contains_result, op))
385+
0, op->completionKey(), op))
384386
{
385387
// Out of resources. Put on completed queue instead.
386388
mutex::scoped_lock lock(dispatch_mutex_);
@@ -401,8 +403,9 @@ void win_iocp_io_context::on_completion(win_iocp_operation* op,
401403
op->OffsetHigh = bytes_transferred;
402404

403405
// Enqueue the operation on the I/O completion port.
406+
op->completionKey() = overlapped_contains_result;
404407
if (!::PostQueuedCompletionStatus(iocp_.handle,
405-
0, overlapped_contains_result, op))
408+
0, op->completionKey(), op))
406409
{
407410
// Out of resources. Put on completed queue instead.
408411
mutex::scoped_lock lock(dispatch_mutex_);

asio/include/asio/detail/win_iocp_operation.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class win_iocp_operation
5959
OffsetHigh = 0;
6060
hEvent = 0;
6161
ready_ = 0;
62+
completionKey_ = 0;
63+
}
64+
65+
ULONG_PTR& completionKey() {
66+
return completionKey_;
6267
}
6368

6469
protected:
@@ -68,7 +73,8 @@ class win_iocp_operation
6873

6974
win_iocp_operation(func_type func)
7075
: next_(0),
71-
func_(func)
76+
func_(func),
77+
completionKey_(0)
7278
{
7379
reset();
7480
}
@@ -84,6 +90,7 @@ class win_iocp_operation
8490
win_iocp_operation* next_;
8591
func_type func_;
8692
long ready_;
93+
ULONG_PTR completionKey_;
8794
};
8895

8996
} // namespace detail

0 commit comments

Comments
 (0)