Skip to content

github.Client is not safe for concurrent use; is that intended or a bug? #253

Description

@dmitshur

From https://godoc.org/net/http:

Clients and Transports are safe for concurrent use by multiple goroutines and for efficiency should only be created once and re-used.

https://godoc.org/github.com/google/go-github/github#Client makes no such claims, which is why I'm unsure if this is a bug or intended behavior.

However, given that it looks and feels a lot like http.Client, I thought it might also support concurrent use by multiple goroutines and for efficiency should only be created once and re-used.

That's not the case. If you look at the source of github.Client.Do:

c.Rate = response.Rate

It writes to c.Rate without any mutexes, which is not safe and will cause data races:

WARNING: DATA RACE
Write by goroutine 93:
  github.com/google/go-github/github.(*Client).Do()
      .../src/github.com/google/go-github/github/github.go:310 +0x16b

Is that intended, or is this a bug?

If I want to make concurrent calls to GitHub API via multiple goroutines, should I create multiple github.Clients?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions