fix(spanner): replace multiplexed session request loop with shared in-flight creation (#14215)

Fixes: https://github.com/googleapis/google-cloud-go/issues/14212

Reworked multiplexed session initialization to use a shared in-flight
creation latch instead of the old request
goroutine and unbuffered channels. This fixes the startup deadlock
triggered by a cancelled read-only transaction
waiter and adds regression coverage for cancellation and client shutdown
while session creation is in flight.
  
sessionManager used an unbuffered multiplexedSessionReq channel and a
single goroutine to coordinate multiplexed session creation. A cancelled
waiter could cause that goroutine to return, leaving future callers
blocked forever trying to send on the request channel during
takeMultiplexed.

Replace that request/ack flow with a shared in-flight creation record on
sessionManager. When no multiplexed session exists, the manager starts
one background creation with a manager-owned context and exposes a done
channel for all waiters in that creation epoch. Waiters now block on
done or their own context, and completion is broadcast by closing the
shared channel. This removes the deadlock where one cancelled context
could kill shared coordination, and it also lets Client.Close release
any waiters blocked behind an in-flight initial create.
3 files changed
tree: 1b88e850dfd3f2dec4e9c41ce1d58eba0cd0c4e6
  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. apps/
  20. area120/
  21. artifactregistry/
  22. asset/
  23. assuredworkloads/
  24. auditmanager/
  25. auth/
  26. automl/
  27. backupdr/
  28. baremetalsolution/
  29. batch/
  30. beyondcorp/
  31. bigquery/
  32. bigtable/
  33. billing/
  34. binaryauthorization/
  35. capacityplanner/
  36. certificatemanager/
  37. ces/
  38. channel/
  39. chat/
  40. chronicle/
  41. civil/
  42. cloudbuild/
  43. cloudcontrolspartner/
  44. clouddms/
  45. cloudprofiler/
  46. cloudquotas/
  47. cloudsecuritycompliance/
  48. cloudtasks/
  49. commerce/
  50. compute/
  51. confidentialcomputing/
  52. config/
  53. configdelivery/
  54. contactcenterinsights/
  55. container/
  56. containeranalysis/
  57. datacatalog/
  58. dataflow/
  59. dataform/
  60. datafusion/
  61. datalabeling/
  62. datamanager/
  63. dataplex/
  64. dataproc/
  65. dataqna/
  66. datastore/
  67. datastream/
  68. deploy/
  69. developerconnect/
  70. devicestreaming/
  71. dialogflow/
  72. discoveryengine/
  73. dlp/
  74. documentai/
  75. domains/
  76. edgecontainer/
  77. edgenetwork/
  78. errorreporting/
  79. essentialcontacts/
  80. eventarc/
  81. filestore/
  82. financialservices/
  83. firestore/
  84. functions/
  85. geminidataanalytics/
  86. gkebackup/
  87. gkeconnect/
  88. gkehub/
  89. gkemulticloud/
  90. gkerecommender/
  91. grafeas/
  92. gsuiteaddons/
  93. httpreplay/
  94. hypercomputecluster/
  95. iam/
  96. iap/
  97. identitytoolkit/
  98. ids/
  99. internal/
  100. iot/
  101. kms/
  102. language/
  103. licensemanager/
  104. lifesciences/
  105. locationfinder/
  106. logging/
  107. longrunning/
  108. lustre/
  109. maintenance/
  110. managedidentities/
  111. managedkafka/
  112. maps/
  113. mediatranslation/
  114. memcache/
  115. memorystore/
  116. metastore/
  117. migrationcenter/
  118. modelarmor/
  119. monitoring/
  120. netapp/
  121. networkconnectivity/
  122. networkmanagement/
  123. networksecurity/
  124. networkservices/
  125. notebooks/
  126. optimization/
  127. oracledatabase/
  128. orchestration/
  129. orgpolicy/
  130. osconfig/
  131. oslogin/
  132. parallelstore/
  133. parametermanager/
  134. phishingprotection/
  135. policysimulator/
  136. policytroubleshooter/
  137. privatecatalog/
  138. privilegedaccessmanager/
  139. profiler/
  140. pubsub/
  141. pubsublite/
  142. rapidmigrationassessment/
  143. recaptchaenterprise/
  144. recommendationengine/
  145. recommender/
  146. redis/
  147. resourcemanager/
  148. retail/
  149. rpcreplay/
  150. run/
  151. saasplatform/
  152. scheduler/
  153. secretmanager/
  154. securesourcemanager/
  155. security/
  156. securitycenter/
  157. securitycentermanagement/
  158. securityposture/
  159. servicecontrol/
  160. servicedirectory/
  161. servicehealth/
  162. servicemanagement/
  163. serviceusage/
  164. shell/
  165. shopping/
  166. spanner/
  167. speech/
  168. storage/
  169. storagebatchoperations/
  170. storageinsights/
  171. storagetransfer/
  172. streetview/
  173. support/
  174. talent/
  175. telcoautomation/
  176. texttospeech/
  177. third_party/
  178. tpu/
  179. trace/
  180. translate/
  181. vectorsearch/
  182. vertexai/
  183. video/
  184. videointelligence/
  185. vision/
  186. visionai/
  187. vmmigration/
  188. vmwareengine/
  189. vpcaccess/
  190. webrisk/
  191. websecurityscanner/
  192. workflows/
  193. workloadmanager/
  194. workstations/
  195. .gitignore
  196. CHANGES.md
  197. CODE_OF_CONDUCT.md
  198. CONTRIBUTING.md
  199. debug.md
  200. doc.go
  201. go.mod
  202. go.sum
  203. LICENSE
  204. migration.md
  205. README.md
  206. RELEASING.md
  207. SECURITY.md
  208. 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