Fetch to Google APIs timeout in prod

Im getting some strange behaviour in prod when my worker's fetch to googleapis is hanging / timing out. When I run request via curl with the same params, the request succeeds. Am I missing something obvious? Im not using the google node library, Im just making a standard HTTP request. Everything works ok in dev so Im trying to figure out what about the prod worker doesnt work right. curl -X POST \ -H "Content-Type: application/x-www-form-urlencoded" \ --data-urlencode "client_id={GOOGLE_OAUTH_CLIENT_ID}" \ --data-urlencode "client_secret={GOOGLE_OAUTH_SECRET}" \ --data-urlencode "refresh_token={USER_REFRESH_TOKEN}" \ --data-urlencode "grant_type=refresh_token" \ "https://oauth2.googleapis.com/token"
4 Replies
ajgeiss0702
ajgeiss07026d ago
can you show the worker code that is making the http request?
sdr
sdrOP6d ago
Its part of a broader app but its a react-router app which has a loader function. I have a GoogleClient class which I init with the relevant client id, secret, and user refresh token. The fetch call which hangs looks like this
const response = await fetch('https://oauth2.googleapis.com/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
client_id: this.clientId,
client_secret: this.clientSecret,
refresh_token: this.integration.refreshToken!,
grant_type: 'refresh_token',
}),
signal,
})
const response = await fetch('https://oauth2.googleapis.com/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
client_id: this.clientId,
client_secret: this.clientSecret,
refresh_token: this.integration.refreshToken!,
grant_type: 'refresh_token',
}),
signal,
})
I pass in an abort controller signal which I used to kill the request after 10s It works in local dev, and when I copy the same prod params and use them in a curl command it works so Im thinking its a runtime environment thing? But I could be dumb and just not see something obvious, but at this stage Im blind
ajgeiss0702
ajgeiss07026d ago
yeah I don't see anything super obviously wrong there. I have never touched reat-router and know nothing about it. I would make sure that if it provides its own fetch function that there isn't something there that could be messing it up. Also make sure that it only calls fetch within a request handler, as calling fetch outside of a request handler works in local dev but not in prod iirc. A troubleshooting step to consider is to try making a vanilla worker that just calls that api, and see if it works there
sdr
sdrOP6d ago
Yeah good advice, I think I need to just pare it back a basic implementation to identify the problem. I havent had problems with fetch before to other services in other react-router apps on cloudflare Its prob something small and dumb. If not I'll spin up a separate node app on railway or something and see if it just works there Thanks for your help!

Did you find this page helpful?