Comments (9)
@gmlewis yes, exactly. That's the scenario I've encountered.
After instantiating a new github client (client := github.NewClient(http.DefaultClient)
) and having performed some operations (specifically calls to workflow and jobs listings), other controller using the http.DefaultClient started failing with 201 responses (Using a Bearer Token
auth, through the Authorization header).
Changing the http.DefaultClient
to a new &http.Client{}
or even just using that controller before the github instance, worked successfully. Also changing it on the github.NewClient() call
using &http.Client{}
, and leaving the other controller with the default one, worked.
That made me infer that the http.DefaultClient
was being corrupted. Of course this have been debugged from the ground: Checked token, auth, etc... This actually took me several hours to get into the real issue.
Note: #1173 can be related.
from go-github.
The operations executed with the github client where (at least) the http.DefaultClient
is being supposedly corrupted are:
runs, resp, err := c.client.Actions.ListWorkflowRunsByID(ctx, GHOrg, GHChartsRepo, GHChartsWorkflowID, &opts)
jobs, _, err := c.client.Actions.ListWorkflowJobs(ctx, GHOrg, GHChartsRepo, *(run.ID), &github.ListWorkflowJobsOptions{})
url, _, err := c.client.Actions.GetWorkflowJobLogs(ctx, GHOrg, GHChartsRepo, *(job.ID), 2)
from go-github.
Oh, and the client is instantiated with:
client := github.NewClient(http.DefaultClient).WithAuthToken("mytoken")
Which could be also a point where the issue is happening.
Hope it helps.
from go-github.
So first off, to immediately get to the bottom of this, please run your program again under delve the Go debugger, set a watch on http.DefaultClient
and see what modifies it.
Once you have clearly identified the file and line number in this repo that is modifying http.DefaultClient
, please create a minimal example main.go
program that reliably reproduces the problem and post it here. We can then work on a solution.
from go-github.
I'm hoping this will be fixed by #3011.
from go-github.
Working succesfully after forcing go.mod
from commit a354a6c
github.com/google/go-github/v57 v57.0.1-0.20231218013855-a354a6c89032
Thank you, @gmlewis
from go-github.
You are saying that the actual http.DefaultClient
is being corrupted and values within it are being overwritten?
from go-github.
Just saw https://github.com/google/go-github/blob/master/github/github.go#L318
func NewClient(httpClient *http.Client) *Client {
c := &Client{client: httpClient}
c.initialize()
return c
}
Since both the client
field and the httpClient
are pointers, I think c
its being instantiated with a direct reference here c := &Client{client: httpClient}
. Then, in the initialize() function seems to be modified. Probably c.Authorizations = (*AuthorizationsService)(&c.common)
is the key of the bearer auth problem later on using the client.
Probably making a value-clone, kind of:
httpClientValue := &httpClient
c := &Client{client: *httpClientValue}
would solve the issue (but we would be also missing the point of using a pointer injection on func NewClient(httpClient *http.Client)
, so not sure if that's the best solution: and changing it would be a hell of a breaking change).
Other option without breaking changes would be having a NewClient()
constructor that would instantiate an empty client inside, declaring this issue as an expected behavior. I just saw NewClient(nil)
calls out there but IMHO they don't seem very nice to see, so probably a NewClient()
would be more concise to any user.
from go-github.
Sorry for the waiting. Here's the snippet:
func main() {
github.NewClient(http.DefaultClient).WithAuthToken("myToken")
req, _ := http.NewRequest(http.MethodGet, "myapiEndpoint", nil)
req.Header.Set("Authorization", "Bearer myToken")
resp, _ := http.DefaultClient.Do(req)
}
´http.DefaultClient.Transport´ pass from nil
to github.com/google/go-github/v57/github.(*Client).WithAuthToken.func1´ when watching its value after the
github.NewClient(http.DefaultClient).WithAuthToken(...)` call, and in my API (internal) I receive a 201 Status Code (can't say exactly why, trying other API's it feels that an Authentication header is still being sent, since response is "bad token" instead "no token". But in some way the client is corrupted.
from go-github.
Related Issues (20)
- Implementing Personal Access Tokens API HOT 5
- Missing fields in structure HOT 6
- json: cannot unmarshal array into Go value of type github.Repository HOT 1
- Revert mistakenly added fields in DraftReviewComment HOT 1
- A callback to go with SleepUntilPrimaryRateLimitResetWhenRateLimited? HOT 7
- Add support for merge queue parameters for organization and repository ruleset HOT 2
- Unable to create Custom Repository Role without permissions HOT 6
- Unable to Parse Private Key HOT 8
- Error when parsing repository that uses multiselect custom-properties HOT 5
- Adding beta feature for rulesets HOT 1
- Idea: auto fix for fmt and codegen HOT 1
- GetHasWiki returns true/false based only on the repository setting HOT 1
- ProvisionAndInviteSCIMUser query instead body HOT 4
- Rulesets - do not require status checks on creation
- Having ListOptions and ListCursorOptions in AlertListOptions creates ambiguity HOT 7
- repository rulesets are missing the source attribute for the property condition HOT 5
- `MetaService.Get` fails because the schema of the JSON in the API response is different from the expected in `APIMeta.Domains` type HOT 3
- Feature request: support Deployment Review Event, Review Custom Deployment Protection Rule API HOT 2
- explain
- OrganizationsService.GetPackage escapes packagName, but UserService.GetPackage does not HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-github.