Fix invalid credentials error.#10
Conversation
|
So, I reverted the changes here and no longer had a problem. Very strange. |
|
This was a learning experience: Since I cache the Github clients when looping over repositories in the handler, I believe the errors were caused by expired tokens from getting the same Lambda container for >1h. The fix will be to make sure we start with fresh clients every time the lambda is invoked. |
|
This explains the case for nodejs, it should be similar in go https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/. Basically the function can skip initialization and go directly to executing the function. Which means there could be things cached from previous runs. |
|
Will test the current code in the wild. There is more work to be done though:
|
|
The updated Lambda has been deployed and tested, and refreshing workers in case the token is expired seems to work fine. I think we should merge this as is and roll it out, and then write a test case for rotating clients in the future (probably will require mocking |
This fixes a problem where
listKeysresponded with401 Bad credentials. However, I can't really explain WHY it fixes the problem.According to the docs:
https://golang.org/pkg/context/#Background
context.Background()"is never canceled, has no values, and has no deadline". However, it seems like it was somehow cancelled since Github stopped responding with 401 after I changed tocontext.TODO().According to the oauth2 docs:
https://godoc.org/golang.org/x/oauth2
You should be able to use either
context.Background()orcontext.TODO()if you are not passing an actual context in. Not sure whats up here.