fix(firestore): bubble up errors in BulkWriter  (#14481)

This PR addresses an issue where the Firestore `BulkWriter` could
silently fail to persist documents without notifying the caller. This
behavior was primarily observed when the `BulkWriter`'s context was
canceled or when internal limits were reached.

#### Root Causes
1. **Dropped Batches on Cancellation:** In the background `send`
function, if the context was canceled, the current batch of jobs was
dropped immediately without notifying the individual job result channels
.
2. **Ignored Queuing Errors:** The `write` function and the retry logic
ignored errors returned by the underlying bundler when attempting to
queue a write .
3. **Ignored Rate Limit Errors:** Context errors occurring during the
rate limiter's wait period were not checked or propagated .

#### Changes
- Updated the internal `write` method and its public callers (`Create`,
`Delete`, `Set`, and `Update`) to return errors from the rate limiter
and the bundler.
- Modified the `send` function to iterate through and notify all jobs in
a batch with a context error if the transmission is aborted due to
cancellation.
- Added error checking to the retry logic within `send` to ensure
failures to re-queue a job are surfaced.

These changes ensure that any failure to queue or send a document is
explicitly reported through the `BulkWriterJob` results or as an
immediate return value, preventing data loss.

#11422.

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2 files changed
tree: e6ad528e920e4dbd37bf030320da31a3e1dee9f4
  1. .gemini/
  2. .github/
  3. .librarian/
  4. accessapproval/
  5. accesscontextmanager/
  6. advisorynotifications/
  7. ai/
  8. aiplatform/
  9. alloydb/
  10. analytics/
  11. apigateway/
  12. apigeeconnect/
  13. apigeeregistry/
  14. apihub/
  15. apikeys/
  16. apiregistry/
  17. appengine/
  18. apphub/
  19. appoptimize/
  20. apps/
  21. area120/
  22. artifactregistry/
  23. asset/
  24. assuredworkloads/
  25. auditmanager/
  26. auth/
  27. automl/
  28. backupdr/
  29. baremetalsolution/
  30. batch/
  31. beyondcorp/
  32. biglake/
  33. bigquery/
  34. bigtable/
  35. billing/
  36. binaryauthorization/
  37. capacityplanner/
  38. certificatemanager/
  39. ces/
  40. channel/
  41. chat/
  42. chronicle/
  43. civil/
  44. cloudbuild/
  45. cloudcontrolspartner/
  46. clouddms/
  47. cloudprofiler/
  48. cloudquotas/
  49. cloudsecuritycompliance/
  50. cloudtasks/
  51. commerce/
  52. compute/
  53. confidentialcomputing/
  54. config/
  55. configdelivery/
  56. contactcenterinsights/
  57. container/
  58. containeranalysis/
  59. datacatalog/
  60. dataflow/
  61. dataform/
  62. datafusion/
  63. datalabeling/
  64. datamanager/
  65. dataplex/
  66. dataproc/
  67. dataqna/
  68. datastore/
  69. datastream/
  70. deploy/
  71. developerconnect/
  72. devicestreaming/
  73. dialogflow/
  74. discoveryengine/
  75. dlp/
  76. documentai/
  77. domains/
  78. edgecontainer/
  79. edgenetwork/
  80. errorreporting/
  81. essentialcontacts/
  82. eventarc/
  83. filestore/
  84. financialservices/
  85. firestore/
  86. functions/
  87. geminidataanalytics/
  88. gkebackup/
  89. gkeconnect/
  90. gkehub/
  91. gkemulticloud/
  92. gkerecommender/
  93. grafeas/
  94. gsuiteaddons/
  95. httpreplay/
  96. hypercomputecluster/
  97. iam/
  98. iap/
  99. identitytoolkit/
  100. ids/
  101. internal/
  102. iot/
  103. kms/
  104. language/
  105. licensemanager/
  106. lifesciences/
  107. locationfinder/
  108. logging/
  109. longrunning/
  110. lustre/
  111. maintenance/
  112. managedidentities/
  113. managedkafka/
  114. maps/
  115. mediatranslation/
  116. memcache/
  117. memorystore/
  118. metastore/
  119. migrationcenter/
  120. modelarmor/
  121. monitoring/
  122. netapp/
  123. networkconnectivity/
  124. networkmanagement/
  125. networksecurity/
  126. networkservices/
  127. notebooks/
  128. optimization/
  129. oracledatabase/
  130. orchestration/
  131. orgpolicy/
  132. osconfig/
  133. oslogin/
  134. parallelstore/
  135. parametermanager/
  136. phishingprotection/
  137. policysimulator/
  138. policytroubleshooter/
  139. privatecatalog/
  140. privilegedaccessmanager/
  141. profiler/
  142. pubsub/
  143. pubsublite/
  144. rapidmigrationassessment/
  145. recaptchaenterprise/
  146. recommendationengine/
  147. recommender/
  148. redis/
  149. resourcemanager/
  150. retail/
  151. rpcreplay/
  152. run/
  153. saasplatform/
  154. scheduler/
  155. secretmanager/
  156. securesourcemanager/
  157. security/
  158. securitycenter/
  159. securitycentermanagement/
  160. securityposture/
  161. servicecontrol/
  162. servicedirectory/
  163. servicehealth/
  164. servicemanagement/
  165. serviceusage/
  166. shell/
  167. shopping/
  168. spanner/
  169. speech/
  170. storage/
  171. storagebatchoperations/
  172. storageinsights/
  173. storagetransfer/
  174. streetview/
  175. support/
  176. talent/
  177. telcoautomation/
  178. texttospeech/
  179. third_party/
  180. tpu/
  181. trace/
  182. translate/
  183. vectorsearch/
  184. vertexai/
  185. video/
  186. videointelligence/
  187. vision/
  188. visionai/
  189. vmmigration/
  190. vmwareengine/
  191. vpcaccess/
  192. webrisk/
  193. websecurityscanner/
  194. workflows/
  195. workloadmanager/
  196. workstations/
  197. .gitignore
  198. CHANGES.md
  199. CODE_OF_CONDUCT.md
  200. CONTRIBUTING.md
  201. debug.md
  202. doc.go
  203. go.mod
  204. go.sum
  205. librarian.yaml
  206. LICENSE
  207. migration.md
  208. README.md
  209. RELEASING.md
  210. SECURITY.md
  211. testing.md
README.md

Google Cloud Client Libraries for Go

Go Reference

Go packages for Google Cloud Platform services.

Installation

go get cloud.google.com/go/firestore@latest # Replace firestore with the package you want to use.

NOTE: Some of these packages are under development, and may occasionally make backwards-incompatible changes.

Supported APIs

For an updated list of all of our released APIs please see our reference docs.

Go Versions Supported

Our libraries are compatible with the two most recent major Go releases, the same policy the Go programming language follows. This means the currently supported versions are:

  • Go 1.25
  • Go 1.26

Authentication

By default, each client library will use Application Default Credentials (ADC) to automatically configure the credentials used in calling the API endpoint. When using the libraries in a Google Cloud Platform environment such as Compute Engine, Kubernetes Engine, or App Engine, no additional authentication steps are necessary. See Authentication methods at Google and Authenticate for using client libraries for more information.

client, err := storage.NewClient(ctx)

For applications running elsewhere, such as your local development environment, you can use the gcloud auth application-default login command from the Google Cloud CLI to set user credentials in your local filesystem. Application Default Credentials will automatically detect these credentials. See Set up ADC for a local development environment for more information.

Alternately, you may need to provide an explicit path to your credentials. To authenticate using a service account key file, either set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path to your key file, or programmatically pass option.WithCredentialsFile to the NewClient function of the desired package. For example:

client, err := storage.NewClient(ctx, option.WithCredentialsFile("path/to/keyfile.json"))

You can exert even more control over authentication by using the credentials package to create an auth.Credentials. Then pass option.WithAuthCredentials to the NewClient function:

creds, err := credentials.DetectDefault(&credentials.DetectOptions{...})
...
client, err := storage.NewClient(ctx, option.WithAuthCredentials(creds))

Contributing

Contributions are welcome. Please, see the CONTRIBUTING document for details.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Contributor Code of Conduct for more information.

Links