Skip to content

Commit ca99370

Browse files
Relax the WaitQueue fairness requirement in the CMAP spec (#1738)
Co-authored-by: Matt Dale <[email protected]>
1 parent f321471 commit ca99370

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,10 @@ A concept that represents pending requests for [Connections](#connection). When
244244
either receives a [Connection](#connection) or times out. A WaitQueue has the following traits:
245245

246246
- **Thread-Safe**: When multiple threads attempt to enter or exit a WaitQueue, they do so in a thread-safe manner.
247-
- **Ordered/Fair**: When [Connections](#connection) are made available, they are issued out to threads in the order that
248-
the threads entered the WaitQueue.
247+
- **Ordered/fair**: When [Connections](#connection) are made available, they SHOULD be issued out to threads in the
248+
order that the threads entered the WaitQueue. If this is behavior poses too much of an implementation burden, then
249+
at the very least threads that have entered the queue more recently MUST NOT be intentionally prioritized over those
250+
that entered it earlier.
249251
- **Timeout aggressively:** Members of a WaitQueue MUST timeout if they are enqueued for longer than the computed
250252
timeout and MUST leave the WaitQueue immediately in this case.
251253

@@ -557,7 +559,7 @@ MUST wait to service the request until neither of those two conditions are met o
557559
becomes available, re-entering the checkOut loop in either case. This waiting MUST NOT prevent
558560
[Connections](#connection) from being checked into the pool. Additionally, the Pool MUST NOT service any newer checkOut
559561
requests before fulfilling the original one which could not be fulfilled. For drivers that implement the WaitQueue via a
560-
fair semaphore, a condition variable may also be needed to to meet this requirement. Waiting on the condition variable
562+
fair semaphore, a condition variable may also be needed to meet this requirement. Waiting on the condition variable
561563
SHOULD also be limited by the WaitQueueTimeout, if the driver supports one and it was specified by the user.
562564

563565
If the pool is "closed" or "paused", any attempt to check out a [Connection](#connection) MUST throw an Error. The error
@@ -1258,12 +1260,11 @@ These options were originally only implemented in three drivers (Java, C#, and P
12581260
these fields would allow for faster diagnosis of issues in the connection pool, they would not actually prevent an error
12591261
from occurring.
12601262

1261-
Additionally, these options have the effect of prioritizing older requests over newer requests, which is not necessarily
1262-
the behavior that users want. They can also result in cases where queue access oscillates back and forth between full
1263-
and not full. If a driver has a full waitQueue, then all requests for [Connections](#connection) will be rejected. If
1264-
the client is continually spammed with requests, you could wind up with a scenario where as soon as the waitQueue is no
1265-
longer full, it is immediately filled. It is not a favorable situation to be in, partially b/c it violates the fairness
1266-
guarantee that the waitQueue normally provides.
1263+
Additionally, these options have the effect of prioritizing newer requests over older requests, which is not necessarily
1264+
the behavior that users want. For example, consider a situation when a WaitQueue is full, and a request for
1265+
[Connection](#connection) gets rejected. Then a spot opens in the WaitQueue, and a newer request gets accepted. One may
1266+
say that the newer request was prioritized over the older one, which violates the fairness recommendation that the
1267+
WaitQueue normally adheres to.
12671268

12681269
Because of these issues, it does not make sense to
12691270
[go against driver mantras and provide an additional knob](../driver-mantras.md#). We may eventually pursue an
@@ -1374,6 +1375,8 @@ to close and remove from its pool a [Connection](#connection) which has unread e
13741375

13751376
## Changelog
13761377

1378+
- 2024-11-27: Relaxed the WaitQueue fairness requirement.
1379+
13771380
- 2024-11-01: Fixed race condition in pool-checkout-returned-connection-maxConnecting.yml test.
13781381

13791382
- 2024-01-23: Migrated from reStructuredText to Markdown.

0 commit comments

Comments
 (0)