<!-- llms-explorer concept facts · https://llms-explorer.com/tree/deadline-propagation-and-context-cancellation-in-mongodb-drivers/ · pack 2026-10-15 · ~4180 tokens -->

# Deadline Propagation and Context Cancellation in MongoDB Drivers

> Depth-first rabbithole dossier for Deadline Propagation and Context Cancellation in MongoDB Drivers; source-anchored research pack.

Parent: [Client Side Operations Timeout (CSOT)](https://llms-explorer.com/tree/client-side-operations-timeout-csot/) · 3 facets · 40 facts · page: https://llms-explorer.com/tree/deadline-propagation-and-context-cancellation-in-mongodb-drivers/

## How it works

- [low] When retrieving a connection, the driver sets the socket's read or write deadline to the shorter of the Context deadline or the socket timeout. Sources: https://www.mongodb.com/docs/drivers/go/current/context.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] The driver considers a Context expired when an operation exceeds its timeout or is canceled, checking expiration via the Done() method. Sources: https://www.mongodb.com/docs/drivers/go/current/context.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] When creating a new connection, the driver sets the Context timeout for establishment to the shorter of the Context expiration or the connection timeout. Sources: https://www.mongodb.com/docs/drivers/go/current/context.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] WithoutCancel returns a derived Context that is not canceled when the parent is canceled, returning no Deadline or Err and having a nil Done channel. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] When a Context is canceled, all Contexts derived from it are also canceled. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`

## Problems, failure modes and limitations

- [low] If the timeoutMS option is set and expires, drivers must abort all blocking work and return control to the user with an error. Sources: https://raw.githubusercontent.com/mongodb/specifications/master/source/client-side-operations-timeout/client-side-operations-timeout.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] When checking for the MaxTimeMSExpired error, drivers must only verify that the error code is 50 and must not check the code name or error message. Sources: https://raw.githubusercontent.com/mongodb/specifications/master/source/client-side-operations-timeout/client-side-operations-timeout.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] When a timeout expires during a blocking task, drivers must expose the underlying error from the task within the new timeout error type. Sources: https://raw.githubusercontent.com/mongodb/specifications/master/source/client-side-operations-timeout/client-side-operations-timeout.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] Drivers must transform timeout errors from external sources, such as the MaxTimeMSExpired server error, into the new timeout error type. Sources: https://raw.githubusercontent.com/mongodb/specifications/master/source/client-side-operations-timeout/client-side-operations-timeout.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] If a transaction callback returns an error requiring abort, drivers must refresh the timeoutMS value for the abortTransaction operation. Sources: https://raw.githubusercontent.com/mongodb/specifications/master/source/client-side-operations-timeout/client-side-operations-timeout.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] The context package defines Canceled as errors.New("context canceled") and DeadlineExceeded as a specific error type. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] The Cause method returns a non-nil error explaining why a Context was canceled, with the cause set by the first cancellation of the Context or its parents. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] The stringified version of the new timeout error type must include the stringified version of the underlying error as a substring. Sources: https://raw.githubusercontent.com/mongodb/specifications/master/source/client-side-operations-timeout/client-side-operations-timeout.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] In Azure DocumentDB, the maximum memory size for MongoDB queries depends on the tier; for example, the M80 tier has a query memory size limit of approximately 150 MiB. (verified as of 2026-10-15) Sources: https://learn.microsoft.com/en-us/azure/documentdb/limitations — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] Refreshing the timeoutMS for abortTransaction can cause the entire withTransaction call to take up to 2*timeoutMS, a risk deemed worthwhile for transaction cleanup. Sources: https://raw.githubusercontent.com/mongodb/specifications/master/source/client-side-operations-timeout/client-side-operations-timeout.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#methodology`
- [low] In Azure DocumentDB, the cursor lifetime is 10 minutes, and a cursorNotFound error might occur if the cursor exceeds this lifetime. Sources: https://learn.microsoft.com/en-us/azure/documentdb/limitations — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#troubleshooting`

## Facts and statements

- [low] The driver generates a separate goroutine to listen for Context cancellation during Read() or Write() operations, closing the connection if cancellation is detected. Sources: https://www.mongodb.com/docs/drivers/go/current/context.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] The Context type carries deadlines, cancellation signals, and request-scoped values across API boundaries and between processes. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] In driver versions before 1.5.0, Context cancellation is not detected, causing the driver to wait for the Read() or Write() method to return. (verified as of 2026-10-15) Sources: https://www.mongodb.com/docs/drivers/go/current/context.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#troubleshooting`
- [low] Automatic propagation of a deadline from an incoming gRPC call to outgoing calls must be explicitly enabled in some languages like C++, while it is enabled by default in others like Java and Go. Sources: https://grpc.io/docs/guides/deadlines/ — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] A Context may be canceled to stop work, and a Context with a deadline is automatically canceled after the deadline passes. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] The Client Side Operations Timeout (CSOT) applies to all work executed for an operation, including server selection, connection checkout, and server-side execution. Sources: https://raw.githubusercontent.com/mongodb/specifications/master/source/client-side-operations-timeout/client-side-operations-timeout.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] If timeoutMS is set, drivers must apply it to the entire withTransaction call. Sources: https://raw.githubusercontent.com/mongodb/specifications/master/source/client-side-operations-timeout/client-side-operations-timeout.md — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] gRPC converts a deadline to a timeout by deducting the already elapsed time to address deadline propagation. Sources: https://grpc.io/docs/guides/deadlines/ — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] Calling a CancelFunc cancels the child and its children, removes the parent's reference to the child, and stops associated timers. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] WithCancel returns a derived Context with a new Done channel, while WithDeadline returns a derived Context with a deadline adjusted to be no later than the specified time. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] If the parent's deadline is earlier than the specified time, WithDeadline(parent, d) is semantically equivalent to the parent Context. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] A CancelFunc tells an operation to abandon work without waiting for it to stop, and may be called by multiple goroutines simultaneously, with subsequent calls doing nothing. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] Context Values should only be used for request-scoped data transiting processes and APIs, not for passing optional function parameters. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#patterns`
- [low] Failing to call the CancelFunc leaks the child Context and its children until the parent is canceled. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#antipatterns`
- [low] By default, gRPC does not set a deadline, which allows a client to wait for a response indefinitely. Sources: https://grpc.io/docs/guides/deadlines/ — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] If a server exceeds the deadline while processing a request, the client fails the RPC with the DEADLINE_EXCEEDED status. Sources: https://grpc.io/docs/guides/deadlines/ — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] A gRPC server automatically cancels a call with the CANCELLED status once a client-set deadline has passed. Sources: https://grpc.io/docs/guides/deadlines/ — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] The same Context may be passed to functions running in different goroutines, as Contexts are safe for simultaneous use by multiple goroutines. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] AfterFunc arranges to call a function in its own goroutine after the Context is canceled, or immediately if the Context is already canceled. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)). Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] In Azure DocumentDB, tokenization for Chinese, Japanese, and Korean is not supported. Sources: https://learn.microsoft.com/en-us/azure/documentdb/limitations — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#core`
- [low] Contexts should not be stored inside struct types; instead, pass a Context explicitly to each function that requires it. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#patterns`
- [low] Do not pass a nil Context, even if permitted; use context.TODO if the appropriate Context is unknown. Sources: https://pkg.go.dev/context — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#patterns`
- [low] In Azure DocumentDB, unique index builds are performed in the foreground and block writes to the collection. Sources: https://learn.microsoft.com/en-us/azure/documentdb/limitations — source: `~/.global-ai-hub/research/.pipeline/mongodb-2026-10-14/frb/deadline-propagation-and-context-cancellation-in-mongodb-drivers-8f8f771b09/rabbithole-synthesis.md#patterns`

## Related concepts

- Context — is a part of Deadline Propagation and Context Cancellation in MongoDB Drivers
- and — is a part of Deadline Propagation and Context Cancellation in MongoDB Drivers
- MongoDB — is a part of Deadline Propagation and Context Cancellation in MongoDB Drivers
- Deadline — is a part of Deadline Propagation and Context Cancellation in MongoDB Drivers
- Drivers — is a part of Deadline Propagation and Context Cancellation in MongoDB Drivers
- Cancellation — is a part of Deadline Propagation and Context Cancellation in MongoDB Drivers
- Propagation — is a part of Deadline Propagation and Context Cancellation in MongoDB Drivers
