commit | 6114940689b1dffd822bbe77408bce0b0b9d84f7 | [log] [tgz] |
---|---|---|
author | Rohith Ravi <entombedvirus@gmail.com> | Tue May 05 20:16:57 2020 +0000 |
committer | Cody Oss <codyoss@google.com> | Tue May 19 17:09:29 2020 +0000 |
tree | c51cd2205c6fd6c148f032a4b7c9783dd68c335c | |
parent | 896839812b23852af2c5c1ea6702df7beee3de79 [diff] |
support/bundler: fix deadlock when using time based flush bundler.Bundler can run into a deadlock under the following configuration: - handler limit of 1 - high size and count thresholds such that the only reason a bundle is flushed is because of the delay timer expiring Under these conditions, with high concurrency, a deadlock can happen because the background handler goroutine can exit while there is a pending queue, which will never get flushed. Specifically, this sequence of events: - handler goroutine calls postHandle and receives a nil for the next bundle, signaling it has no more work to do. - some other goroutine calls AddWait() -> enqueueCurBundle, which sees that b.handlerLimit cannot be exceeded and proceeds to queue the item - handler goroutine decrements b.handlerLimit and exits The fix is to move the decrement of b.handlerLimit into postHandle such that the decision to exit and allowing a new handler goroutine to be spawned cannot be re-ordered. Fixes: googleapis/google-api-go-client#475 Change-Id: I84421e53a4dc24eec36ceb147933aab57a40aec8 Reviewed-on: https://code-review.googlesource.com/c/google-api-go-client/+/55950 Reviewed-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Cody Oss <codyoss@google.com>
$ go get google.golang.org/api/tasks/v1 $ go get google.golang.org/api/moderator/v1 $ go get google.golang.org/api/urlshortener/v1 ... etc ...
and using:
package main import ( "net/http" "google.golang.org/api/urlshortener/v1" ) func main() { svc, err := urlshortener.New(http.DefaultClient) // ... }
These are auto-generated Go libraries from the Google Discovery Service's JSON description files of the available “new style” Google APIs.
Due to the auto-generated nature of this collection of libraries, complete APIs or specific versions can appear or go away without notice. As a result, you should always locally vendor any API(s) that your code relies upon.
These client libraries are officially supported by Google. However, the libraries are considered complete and are in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.
If you're working with Google Cloud Platform APIs such as Datastore or Pub/Sub, consider using the Cloud Client Libraries for Go instead. These are the new and idiomatic Go libraries targeted specifically at Google Cloud Platform Services.
The generator itself and the code it produces are beta. Some APIs are alpha/beta, and indicated as such in the import path (e.g., “google.golang.org/api/someapi/v1alpha”).
Application Default Credentials provide a simplified way to obtain credentials for authenticating with Google APIs.
The Application Default Credentials authenticate as the application itself, which make them great for working with Google Cloud APIs like Storage or Datastore. They are the recommended form of authentication when building applications that run on Google Compute Engine or Google App Engine.
Default credentials are provided by the golang.org/x/oauth2/google
package. To use them, add the following import:
import "golang.org/x/oauth2/google"
Some credentials types require you to specify scopes, and service entry points may not inject them. If you encounter this situation you may need to specify scopes as follows:
import ( "context" "golang.org/x/oauth2/google" "google.golang.org/api/compute/v1" ) func main() { // Use oauth2.NoContext if there isn't a good context to pass in. ctx := context.Background() client, err := google.DefaultClient(ctx, compute.ComputeScope) if err != nil { //... } computeService, err := compute.New(client) if err != nil { //... } }
If you need a oauth2.TokenSource
, use the DefaultTokenSource
function:
ts, err := google.DefaultTokenSource(ctx, scope1, scope2, ...) if err != nil { //... } client := oauth2.NewClient(ctx, ts)
See also: golang.org/x/oauth2/google package documentation.