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

Request timed out error while using Google provider #3920

Closed
appocal-main opened this issue Feb 11, 2022 · 74 comments
Closed

Request timed out error while using Google provider #3920

appocal-main opened this issue Feb 11, 2022 · 74 comments
Labels
bug Something isn't working

Comments

@appocal-main
Copy link

Description 🐜

After following the docs for Prisma Adapter and Google Provider, I added auth to my repo, but when trying to log in through google auth, it's timing out for some reason.

image

I even tried with a longer timeout, but still no luck :(

providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
      httpOptions: {
        timeout: 10000,
      }
    })
  ],

image

Is this a bug in your own project?

Yes

How to reproduce ☕️

I replicated the issue in a new separate repo, just add the env variable and run it in local - https://github.com/Nikit-Singh/next-auth-google-issue

Screenshots / Logs 📽

No response

Environment 🖥

System:
OS: Windows 10 10.0.22000
CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
Memory: 4.38 GB / 15.95 GB
Binaries:
Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.3.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22000.120.0), Chromium (96.0.1054.62)
Internet Explorer: 11.0.22000.120
npmPackages:
next: 12.0.10 => 12.0.10
next-auth: ^4.2.1 => 4.2.1
react: 17.0.2 => 17.0.2

Contributing 🙌🏽

Yes, I am willing to help solve this bug in a PR

@appocal-main appocal-main added the bug Something isn't working label Feb 11, 2022
@sc0rp10n-py
Copy link

Is there any fix for this?
I am also facing the same issue.

[next-auth][error][OAUTH_CALLBACK_ERROR]
https://next-auth.js.org/errors#oauth_callback_error outgoing request timed out after 3500ms {
  error: {
    message: 'outgoing request timed out after 3500ms',
    stack: 'RPError: outgoing request timed out after 3500ms\n' +
      '    at /home/sc0rp10n/fictional-adventure/node_modules/openid-client/lib/helpers/request.js:136:13\n' +
      '    at async Client.grant (/home/sc0rp10n/fictional-adventure/node_modules/openid-client/lib/client.js:1329:22)\n' +
      '    at async Client.callback (/home/sc0rp10n/fictional-adventure/node_modules/openid-client/lib/client.js:474:24)\n' +
      '    at async oAuthCallback (/home/sc0rp10n/fictional-adventure/node_modules/next-auth/core/lib/oauth/callback.js:112:16)\n' +
      '    at async Object.callback (/home/sc0rp10n/fictional-adventure/node_modules/next-auth/core/routes/callback.js:50:11)\n' +
      '    at async NextAuthHandler (/home/sc0rp10n/fictional-adventure/node_modules/next-auth/core/index.js:139:28)\n' +
      '    at async NextAuthNextHandler (/home/sc0rp10n/fictional-adventure/node_modules/next-auth/next/index.js:21:19)\n' +
      '    at async /home/sc0rp10n/fictional-adventure/node_modules/next-auth/next/index.js:57:32\n' +
      '    at async Object.apiResolver (/home/sc0rp10n/fictional-adventure/node_modules/next/dist/server/api-utils.js:101:9)\n' +
      '    at async DevServer.runApi (/home/sc0rp10n/fictional-adventure/node_modules/next/dist/server/next-server.js:320:9)',
    name: 'RPError'
  },
  providerId: 'google',
  message: 'outgoing request timed out after 3500ms'
}
[next-auth][error][CALLBACK_OAUTH_ERROR]
https://next-auth.js.org/errors#callback_oauth_error outgoing request timed out after 3500ms RPError: outgoing request timed out after 3500ms
    at /home/sc0rp10n/fictional-adventure/node_modules/openid-client/lib/helpers/request.js:136:13
    at async Client.grant (/home/sc0rp10n/fictional-adventure/node_modules/openid-client/lib/client.js:1329:22)
    at async Client.callback (/home/sc0rp10n/fictional-adventure/node_modules/openid-client/lib/client.js:474:24)
    at async oAuthCallback (/home/sc0rp10n/fictional-adventure/node_modules/next-auth/core/lib/oauth/callback.js:112:16)
    at async Object.callback (/home/sc0rp10n/fictional-adventure/node_modules/next-auth/core/routes/callback.js:50:11)
    at async NextAuthHandler (/home/sc0rp10n/fictional-adventure/node_modules/next-auth/core/index.js:139:28)
    at async NextAuthNextHandler (/home/sc0rp10n/fictional-adventure/node_modules/next-auth/next/index.js:21:19)
    at async /home/sc0rp10n/fictional-adventure/node_modules/next-auth/next/index.js:57:32
    at async Object.apiResolver (/home/sc0rp10n/fictional-adventure/node_modules/next/dist/server/api-utils.js:101:9)
    at async DevServer.runApi (/home/sc0rp10n/fictional-adventure/node_modules/next/dist/server/next-server.js:320:9) {
  name: 'OAuthCallbackError',
  code: undefined
}

The same code works fine in production but in localhost this error is coming.

@sc0rp10n-py
Copy link

I just redeployed the local code to another domain using vercel, and it works in production, the bug is only for localhost I think.
Could anyone confirm once?
Any fixes the please tag me.

@kpratik2015
Copy link

Facing same issue only for localhost

@fyt22
Copy link

fyt22 commented Feb 12, 2022

facing the same issue on localhost randomly.

@panva
Copy link
Contributor

panva commented Feb 12, 2022

No bug in sight, your Node.js process may not be able to reach google servers for a variety of local network / network setup related reasons.

@lakshyasharma14
Copy link

I am facing the same issue for the past 24 hours only, the same code worked fine earlier, and I have never encountered this issue before.
@panva
Is there any way to debug this further?
Is there a way I can increase this time out, as in the first update httpOptions : timeout is passed but that seems to be an incorrect way.

@panva
Copy link
Contributor

panva commented Feb 12, 2022

Try NODE_DEBUG=http,https.

I am facing the same issue for the past 24 hours only, the same code worked fine earlier, and I have never encountered this issue before.

openid-client is not the source of your issue then

@balazsorban44
Copy link
Member

Anyone, it's likely a local network issue, but you can set a higher timeout:
#3188

this has also been asked before, please search through old issues/discussions before opening a new one.

#3186

@militiwari
Copy link

Hi, facing the same issue only on localhost. If any solution please write here.

@fyt22
Copy link

fyt22 commented Feb 13, 2022

It seems there is some issue with the auth server, because when I increase the timeout to 40 secs from openid-client it times out again with an error
https://next-auth.js.org/errors#callback_oauth_error connect ETIMEDOUT 13.127.247.216:443 Error: connect ETIMEDOUT 13.127.247.216:443 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) { name: 'OAuthCallbackError', code: 'ETIMEDOUT' }
This is not the right place to discuss this, move it to discussion if you want help.

@AnishDe12020
Copy link

Is this still happening for everyone? It is happening for me, not only with google auth but also with github auth. Was anyone able to find a fix?

@lakshyasharma14
Copy link

It is working fine for me now.

@AnishDe12020
Copy link

AnishDe12020 commented Feb 14, 2022

It is working fine for me now.

Oh, on production or dev? Also, which provider are you using and did you have to set anything else up? (other than clientId and clientSecret)

@lakshyasharma14
Copy link

This issue was only happening with google provider, and not with other providers. If you are having a problem with all the providers it's more of a config /app issue from your side.

@AnishDe12020
Copy link

This issue was only happening with google provider, and not with other providers. If you are having a problem with all the providers it's more of a config /app issue from your side.

Oh, it is happening with GitHub for me as well. I have set all the fields as well -

export default NextAuth({
  adapter: CustomMongooseAdapter(),
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    }),
    GitHubProvider({
      clientId: process.env.GITHUB_CLIENT_ID,
      clientSecret: process.env.GITHUB_CLIENT_SECRET,
    }),
  ],
  callbacks: {
    async session({ session, token, user }) {
      // Store the user's profile in the session
      session.user = user;
      return session;
    },
  },
});

Don't know if I am going wrong anywhere. Also this problem started occuring out of nowhere. Don't know why.

@ahmedelq
Copy link

This issue was only happening with google provider, and not with other providers. If you are having a problem with all the providers it's more of a config /app issue from your side.

It's not working with Github as well.

@lakshyasharma14
Copy link

lakshyasharma14 commented Feb 14, 2022

Can you guys try passing httpOptions with timeout like shown below (40000 is in ms)and check the error, now it won't timeout because of openid-client, but you'll see some error due to network issue with google/github auth server from there you can further check the issue.

GoogleProvider({
      clientId: process.env.GOOGLE_ID,
      clientSecret: process.env.GOOGLE_SECRET,
      httpOptions: {
        timeout: 40000,
      },
    }),

@militiwari
Copy link

Problem solved for me without changing anything.

@ahmedelq
Copy link

It works for Google provider, but not GitHubs.

@ma3ve
Copy link

ma3ve commented Mar 31, 2022

I had this issue on wsl when I switched to windows, it worked as expected. maybe some kind of network issue with wsl?

@tippfelher
Copy link

How is this closed? oO

@ShlokDesai33
Copy link

I'm facing the same issue with the Google Provider too. Increasing the timeout doesn't seem to do any good.

@RainKolwa
Copy link

FYI: It worked for me when using Chrome with Incognito mode.

@mhaslinsky
Copy link

mhaslinsky commented Jul 7, 2022

Same issue, cropped up randomly after working for days in dev (localhost). Works fine when deployed in prod. No changes were made whatsoever to the Nextauth config. Lengthened http timeout to 40s, same error.
'outgoing request timed out after 40000ms'

@Ger4eK
Copy link

Ger4eK commented Jul 20, 2022

Same issue, cropped up randomly after working for days in dev (localhost). Works fine when deployed in prod. No changes were made whatsoever to the Nextauth config. Lengthened http timeout to 40s, same error. 'outgoing request timed out after 40000ms'

Soo did you fix it????

@5thDimensionalVader
Copy link

I had this issue on wsl when I switched to windows, it worked as expected. maybe some kind of network issue with wsl?

Hi, currently using WSL and facing this issue. Tried the timeout 40s as suggested but it doesn't seem to work. How did you fix yours? I was thinking it's an issue with the version of node i'm using.

@fazzaamiarso
Copy link

I faced this issue a couple times with different providers and I get it to work by turning on/off my wifi connection in my laptop.

@dalalRohit
Copy link

this happened with me while i was on "A" wifi.
switched it to "B", issue gone away ;(

@evanlong0803
Copy link

So is this problem solved? 🤨

@anuragchauhan766
Copy link

same issue with me , tried many methods but no solution: tried method:

  1. Wifi restart
  2. using personal mobile data
  3. laptop restart
  4. changed timeout in nextauthoptions

Github provider works well, the problem is only with Google provider

using on wsl2 , window 11

WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.2134

Error message:

[next-auth][error][OAUTH_CALLBACK_ERROR]
https://next-auth.js.org/errors#oauth_callback_error outgoing request timed out after 3500ms {
  error: RPError: outgoing request timed out after 3500ms
      at eval (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]/node_modules/openid-client/lib/helpers/request.js:115:19)
      at async Issuer.discover (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]/node_modules/openid-client/lib/issuer.js:135:30)
      at async openidClient (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/core/lib/oauth/client.js:12:18)
      at async oAuthCallback (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/core/lib/oauth/callback.js:94:24)
      at async Object.callback (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/core/routes/callback.js:18:79)
      at async AuthHandler (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/core/index.js:202:38)
      at async NextAuthRouteHandler (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/next/index.js:50:30)
      at async NextAuth._args$ (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/next/index.js:84:24)
      at async eval (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/future/route-modules/app-route/module.js:254:37) {
    name: 'OAuthCallbackError',
    code: undefined
  },
  providerId: 'google',
  message: 'outgoing request timed out after 3500ms'
}

I solve my issue by upgrading node v18.x.x to node v20.x.x

@evanlong0803
Copy link

This is obviously a network issue, so why is it relevant to node?

@wpalombini
Copy link

This is obviously a network issue, so why is it relevant to node?

Because of the changes that Node v20x. It handles http services differently, I just could not find the details now.
However, upgrading Node is not to real solution.
I found a way to make it work with all node versions, will share soon.

@wpalombini
Copy link

What really made it work for me with all node versions (16.x, 18.x, 20.x) is:

In your /etc/resolv.conf ensure you have
nameserver 8.8.8.8 or any other DNS server you trust.

In your /etc/wsl.conf ensure you have
[network]
generateResolvConf=false

Then I ran this:
sudo chattr +i /etc/resolv.conf

@evanlong0803
Copy link

GoogleProvider({
   httpOptions: {
     agent // Maybe we can solve it here?
   }
})

@anuragchauhan766
Copy link

anuragchauhan766 commented Aug 22, 2023

What really made it work for me with all node versions (16.x, 18.x, 20.x) is:

In your /etc/resolv.conf ensure you have nameserver 8.8.8.8 or any other DNS server you trust.

In your /etc/wsl.conf ensure you have [network] generateResolvConf=false

Then I ran this: sudo chattr +i /etc/resolv.conf

ye this work, by changing the DNS server for wsl issue can be solved.

but the issue can also be solved by changing the DNS in the windows setting then you don't have to change anything in wsl.conf because by default wsl use window host dns settings

@enoquetembe
Copy link

Hi, facing the same issue. Is there any solution for this?

@evanlong0803
Copy link

There seems to be no decent solution.

@enoquetembe
Copy link

enoquetembe commented Aug 23, 2023

There seems to be no decent solution.

That sucks! How is this closed?

@darq37
Copy link

darq37 commented Sep 18, 2023

I resolved timeout issues by adding this to my code:

const dns = require('dns');
dns.setDefaultResultOrder('ipv4first');

As it turns out, it was a dns issue

@546245234
Copy link

solved by useing clash for windows, open Tun mode,System proxy and Service manager
image

@evanlong0803
Copy link

@balazsorban44 Actually this problem is not very well solved, why close it ? 🤨,Perhaps this question is more appropriate to move on to the discussion and get a standard answer to this question.

@tehfonsi
Copy link

I'm on Windows and use a Cloudflare tunnel to test sign-in flow and I got the same issue.

@FTAndy
Copy link

FTAndy commented Nov 20, 2023

you can import 'global-agent/bootstrap';

This works for me.

@sujithyadav998
Copy link

I resolved timeout issues by adding this to my code:

const dns = require('dns');
dns.setDefaultResultOrder('ipv4first');

As it turns out, it was a dns issue

This works for me

@oyal
Copy link

oyal commented Dec 14, 2023

solved by useing clash for windows, open Tun mode,System proxy and Service manager image

Hello, I encountered another error after turning on TUN Mode and Service Mode. Do you know what the reason is?

[next-auth][error][SIGNIN_OAUTH_ERROR] 
https://next-auth.js.org/errors#signin_oauth_error Client network socket disconnected before secure TLS connection was established {
  error: {
    message: 'Client network socket disconnected before secure TLS connection was established',
    stack: 'Error: Client network socket disconnected before secure TLS connection was established\n' +
      '    at connResetException (node:internal/errors:787:14)\n' +
      '    at TLSSocket.onConnectEnd (node:_tls_wrap:1727:19)\n' +
      '    at TLSSocket.emit (node:events:526:35)\n' +
      '    at endReadableNT (node:internal/streams/readable:1589:12)\n' +
      '    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)',
    name: 'Error'
  },
  providerId: 'google',
  message: 'Client network socket disconnected before secure TLS connection was established'
}

image

@jakar79
Copy link

jakar79 commented Feb 12, 2024

export default NextAuth({
providers: [

GoogleProvider({
  clientId: process.env.GOOGLE_ID,
  clientSecret: process.env.GOOGLE_SECRET,
}),

],
callbacks:{
adapter: MongoDBAdapter(clientPromise),
}
})

@foreverLoveWisdom
Copy link

foreverLoveWisdom commented Mar 5, 2024

Can you guys try passing httpOptions with timeout like shown below (40000 is in ms)and check the error, now it won't timeout because of openid-client, but you'll see some error due to network issue with google/github auth server from there you can further check the issue.

GoogleProvider({
      clientId: process.env.GOOGLE_ID,
      clientSecret: process.env.GOOGLE_SECRET,
      httpOptions: {
        timeout: 40000,
      },
    }),
  • Confirming that the solution works for me. I only encountered this problem on localhost, and I use a custom identity provider. I guess it somehow relates to my local network.🥲

@elaine202310
Copy link

image
i tried all the methods you guys mentioned, still not work,

@elaine202310
Copy link

image i tried all the methods you guys mentioned, still not work,

i change it to sign in with github, problem solved, it's the problem happens with google provider. it's been confused me for two days, finally!!

@jvtroyen
Copy link

jvtroyen commented May 24, 2024

I have the exact same problem with AzureADProvider, which doesn't even seem to have a timeout setting.
Not only local, but also on PRD (Azure hosted).

Was using node 18, but problem also occurs in 20 and 22

@kamjin1996
Copy link

solved by useing clash for windows, open Tun mode,System proxy and Service manager image

I solved the problem in this way, and it turned out to be a network problem. Anyway, as long as the node process can access the Google server normally, it is feasible. Thank you, Sir.

@wys1010
Copy link

wys1010 commented Sep 16, 2024

solved by useing clash for windows, open Tun mode,System proxy and Service manager image

Thank you very much, my problem has been solved through this method.

@m8nt0
Copy link

m8nt0 commented Nov 7, 2024

L bug

@kiinoo
Copy link

kiinoo commented Dec 25, 2024

same problem, not solved in year 2025!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests