fix(datastore): add retries to emulator (#14591)

**Summary**
This PR refines the Datastore client's resilience logic to fix
regressions identified during TAP testing, specifically regarding
emulator startup races, Unix domain sockets, and IPv6 literals. It
ensures that the resilience benefits for bug
**[b/473841984](http://b/473841984)** are applied consistently to both
production and emulator environments without breaking existing tests.

**Why these changes are needed**
1. **Handling Emulator Startup Races**: Many tests (e.g.,
`exchange:datastore_test`) experience a "connection refused" error if an
RPC is attempted immediately after starting the emulator process. By
adding **`"waitForReady": true`** to the gRPC Service Config, the client
will now block and wait for the emulator to finish binding its port
instead of failing the RPC immediately.
2. **Preventing Infinite Hangs**: With `waitForReady` enabled, an
unreachable host could cause a test to hang indefinitely. This PR adds a
canonical **`"timeout": "60s"`** to the generic `methodConfig` to ensure
RPCs eventually fail with a clear error.
3. **Robust Scheme Handling (Unix Sockets & IPv6)**: Internal test
environments like `tin` often use **Unix domain sockets** (`unix:///`)
or IPv6 literals (`[::1]`) for emulator addresses. Previous logic would
mangle these into invalid targets (e.g., `passthrough:///unix:///...`),
leading to "too many colons" errors or connection hangs. The updated
logic defensively checks for existing valid schemes before applying the
`passthrough:///` optimization.
4. **Idempotent Retries for `Commit`**: A catch-all configuration block
is added to the Service Config to ensure that **`UNAVAILABLE`** errors
are retried for all methods, including `Commit` (used by `PutMulti`),
which was previously omitted.

**Why PR #14411 was insufficient**
While PR #14411 introduced Keepalives and expanded retries for
idempotent calls, it had several gaps:
* It only applied the new configuration to the **production** code path,
leaving the emulator path without resilience logic or standardized
retries.
* By removing the manual 100ms retry loop without adding `waitForReady:
true` to the Service Config, it removed the "wait" period needed for
emulators to become ready.
* The aggressive prepending of `passthrough:///` did not account for
`unix:///` schemes or bracketed IPv6 literals, causing dialer errors in
specialized test environments. (Even though the passthrough was not
added in PR #14411, the current google3 imported code did not have this
logic. While trying to import [cl/906545069](http://cl/906545069) latest
code with psssthrough, this issue was discovered. )

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