Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token for multiple request #81

Closed
anddimario opened this issue Aug 21, 2013 · 10 comments
Closed

Token for multiple request #81

anddimario opened this issue Aug 21, 2013 · 10 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@anddimario
Copy link

Hi, i'm creating a batch script that execute requests with async, there are about 20 requests, and on client request i've this error:

Error: No access or refresh token is set.
    at OAuth2Client.request (/home/andrea/projects/toweb/node_modules/googleapis/lib/auth/oauth2client.js:184:11)
    at /home/andrea/projects/toweb/node_modules/googleapis/lib/auth/oauth2client.js:205:16
    at Request._callback (/home/andrea/projects/toweb/node_modules/googleapis/lib/transporters.js:78:21)
    at Request.self.callback (/home/andrea/projects/toweb/node_modules/googleapis/node_modules/request/index.js:148:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (/home/andrea/projects/toweb/node_modules/googleapis/node_modules/request/index.js:891:14)
    at Request.EventEmitter.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/home/andrea/projects/toweb/node_modules/googleapis/node_modules/request/index.js:842:12)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:883:14

It's a random error and not on a specific request and i think it's something like a timeout on oauth.
Here's the code for a request:

var request_avgtimeonsite =  client.analytics.data.ga.get({ids: 'ga:' + item.id, 'start-date': start_date, 'end-date': end_date, metrics: "ga:avgtimeonsite"}).withAuthClient(oauth2Client);

Have you some suggestions about this problem?

Thanks for your time.
Best regards

@bentona
Copy link
Contributor

bentona commented Aug 24, 2013

Not the maintainer, but more code might help. The construction of your auth client at least?

@anddimario
Copy link
Author

Hi, yes, sorry, here's the code: https://gist.github.com/anddimario/6338925
Sometimes it works without problems, i've tried to set a single client and an oauth for each request, but it seems not work.

Thanks for your time.
Best regards.

@rakyll
Copy link
Contributor

rakyll commented Aug 26, 2013

Is there any chance, this problem is occurring during token refresh? There is a racing condition in this case if there are multiple token refreshing requests are sent out.

@anddimario
Copy link
Author

Hi, i'm looking for use something with async, what do you think it could be the best method to do multiple request?
I've tried the batch system but there are some problems.

Thanks for your time.
Best regards.

@rakyll
Copy link
Contributor

rakyll commented Aug 27, 2013

Google implements OData's batch protocol which cant be consumed by the native HTTP implementation of node which leads to implementing and http client in pure JS or implementing a native OData client. Both are not worth the effort, so I'd suggest using async.

What you can do to avoid your problem, before starting the requests check the expiration date of the token and retrieve a new access token. I'll try to address this in the lib, but temporarily you can solve the problem by making sure your access token is not expired before starting the requests.

@anddimario
Copy link
Author

Hi, i'm usign this link to test my token: https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=
I saw that tokens aren't expired, but the request gave back errors again and the expire time are not refreshed.
I've tested the tokens after and they work.
Could it be some problems with refresh token in oauth method for client?

Thanks for your time.
Best regards

@rakyll
Copy link
Contributor

rakyll commented Sep 3, 2013

Is it possible for to dump the request bodies and headers so I can try to
reproduce your problem? My hypothesis about racy token refreshment is
probably wrong. Even though it's racy, the newly generated access tokens
don't invalidate the previous ones.

On Tue, Sep 3, 2013 at 11:03 AM, anddimario notifications@github.comwrote:

Hi, i'm usign this link to test my token:
https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=
I saw that tokens aren't expired, but the request gave back errors again
and the expire time are not refreshed.
I've tested the tokens after and they work.
Could it be some problems with refresh token in oauth method for client?

Thanks for your time.
Best regards


Reply to this email directly or view it on GitHubhttps://github.com//issues/81#issuecomment-23698595
.

@anddimario
Copy link
Author

Hi, i've created a function to refresh token function and it seems that the principal problem disappears, but i've the resource limit problem, i'm using sleep too, but it seems that client make all request at the same time.

@maxbrodie
Copy link

Hi - I recently used apache bench to load test (100 total reqs, 10 at a time) an API endpoint that uses the client to call a Google API. The benchmark only got to request 32 before node threw:

[Error: No access or refresh token is set.]
at OAuth2Client.request (/webapp/node_modules/googleapis/lib/auth/oauth2client.js:184:11

Any info I can contribute to debug this?

@ryanseys
Copy link
Contributor

Just released 1.0.3 which will likely address this issue. The access token will be refreshed prior to initial request if has expired or is missing and you have a refresh token set. If the request fails due to a missing, invalid, or revoked access token, we will no longer attempt to refresh and re-attempt the request.

https://github.com/google/google-api-nodejs-client/releases/tag/1.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

6 participants