Skip to content

Commit bda4509

Browse files
authored
RUST-1788 Update docs for with_transaction to avoid infinite loop (#998)
1 parent e87f4dd commit bda4509

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/client/session.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,14 @@ impl ClientSession {
581581
/// [`Error::custom`](crate::error::Error::custom) method can accept an arbitrary payload that
582582
/// can be retrieved via [`Error::get_custom`](crate::error::Error::get_custom).
583583
///
584+
/// If a command inside the callback fails, it may cause the transaction on the server to be
585+
/// aborted. This situation is normally handled transparently by the driver. However, if the
586+
/// application does not return that error from the callback, the driver will not be able to
587+
/// determine whether the transaction was aborted or not. The driver will then retry the
588+
/// callback indefinitely. To avoid this situation, the application MUST NOT silently handle
589+
/// errors within the callback. If the application needs to handle errors within the
590+
/// callback, it MUST return them after doing so.
591+
///
584592
/// Because the callback can be repeatedly executed and because it returns a future, the rust
585593
/// closure borrowing rules for captured values can be overly restrictive. As a
586594
/// convenience, `with_transaction` accepts a context argument that will be passed to the

src/sync/client/session.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ impl ClientSession {
142142
/// caller. If the callback needs to provide its own error information, the
143143
/// [`Error::custom`](crate::error::Error::custom) method can accept an arbitrary payload that
144144
/// can be retrieved via [`Error::get_custom`](crate::error::Error::get_custom).
145+
///
146+
/// If a command inside the callback fails, it may cause the transaction on the server to be
147+
/// aborted. This situation is normally handled transparently by the driver. However, if the
148+
/// application does not return that error from the callback, the driver will not be able to
149+
/// determine whether the transaction was aborted or not. The driver will then retry the
150+
/// callback indefinitely. To avoid this situation, the application MUST NOT silently handle
151+
/// errors within the callback. If the application needs to handle errors within the
152+
/// callback, it MUST return them after doing so.
145153
pub fn with_transaction<R, F>(
146154
&mut self,
147155
mut callback: F,

0 commit comments

Comments
 (0)