neonctl icon indicating copy to clipboard operation
neonctl copied to clipboard

`neonctl auth` intermittently and silently fails to open browser

Open jamesbroadhead opened this issue 1 year ago • 1 comments

Steps to reproduce

neonctl auth multiple times

Expected result

Browser opens

Actual result

Command hangs or fails -- approx 1 time in 2 Looks like a race condition starting the OAuth server and trying to connect to it

Environment

Repros easily on my "Macbook Pro 13-inch, 2020, Four Thunderbolt 3 ports" -- maybe happens less on faster hardware?

Logs, links

$ DEBUG=true neonctl auth
DEBUG: Failed to read credentials file Error: ENOENT: no such file or directory, open '/Users/jbo/.config/neonctl/credentials.json'
    at readFileSync (node:fs:448:20)
    at analyticsMiddleware (file:///usr/local/Cellar/neonctl/1.29.3/libexec/lib/node_modules/neonctl/analytics.js:19:29)
    at file:///usr/local/Cellar/neonctl/1.29.3/libexec/lib/node_modules/neonctl/node_modules/yargs/build/lib/middleware.js:82:28
    at Array.reduce (<anonymous>)
    at applyMiddleware (file:///usr/local/Cellar/neonctl/1.29.3/libexec/lib/node_modules/neonctl/node_modules/yargs/build/lib/middleware.js:67:24)
    at CommandInstance.applyMiddlewareAndGetResult (file:///usr/local/Cellar/neonctl/1.29.3/libexec/lib/node_modules/neonctl/node_modules/yargs/build/lib/command.js:242:34)
    at CommandInstance.runCommand (file:///usr/local/Cellar/neonctl/1.29.3/libexec/lib/node_modules/neonctl/node_modules/yargs/build/lib/command.js:128:20)
    at [runYargsParserAndExecuteCommands] (file:///usr/local/Cellar/neonctl/1.29.3/libexec/lib/node_modules/neonctl/node_modules/yargs/build/lib/yargs-factory.js:1386:105)
    at YargsInstance.parse (file:///usr/local/Cellar/neonctl/1.29.3/libexec/lib/node_modules/neonctl/node_modules/yargs/build/lib/yargs-factory.js:707:63)
    at YargsInstance.get [as argv] (file:///usr/local/Cellar/neonctl/1.29.3/libexec/lib/node_modules/neonctl/node_modules/yargs/build/lib/yargs-factory.js:31:30) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/jbo/.config/neonctl/credentials.json'
}
DEBUG: Flushing CLI started event with userId:
DEBUG: Flushed CLI started event with userId:
DEBUG: Discovering oauth server
DEBUG: Sent CLI error event: UNKNOWN_ERROR
ERROR:
DEBUG: Stack: AggregateError [ECONNREFUSED]:
    at internalConnectMultiple (node:net:1117:18)
    at afterConnectMultiple (node:net:1684:7)```
- 

jamesbroadhead avatar May 18 '24 20:05 jamesbroadhead

Public report here: https://x.com/abdul__bayees/status/1791933269845676436

jamesbroadhead avatar May 20 '24 09:05 jamesbroadhead

OP was with:

$ node --version
v22.2.0
$ neonctl --version
1.29.3

Retrying on another machine:

$ neonctl auth
ERROR:
(default) jbo@neon-mb24 ~/checkouts/neon 1 (git: main*)
$ DEBUG=true neonctl auth
DEBUG: Flushing CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Flushed CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Discovering oauth server
DEBUG: Listening on port 64828
^C
(default) jbo@neon-mb24 ~/checkouts/neon 130 (git: main*)
$ DEBUG=true neonctl auth
DEBUG: Flushing CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Flushed CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Discovering oauth server
DEBUG: Listening on port 64845
^C
(default) jbo@neon-mb24 ~/checkouts/neon 130 (git: main*)
$ DEBUG=true neonctl auth
DEBUG: Flushing CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Flushed CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Discovering oauth server
DEBUG: Sent CLI error event: UNKNOWN_ERROR
ERROR:
DEBUG: Stack: AggregateError [ECONNREFUSED]:
    at internalConnectMultiple (node:net:1117:18)
    at afterConnectMultiple (node:net:1684:7)
(default) jbo@neon-mb24 ~/checkouts/neon 1 (git: main*)
$ DEBUG=true neonctl auth
DEBUG: Flushing CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Flushed CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Discovering oauth server
DEBUG: Listening on port 64874
^C
(default) jbo@neon-mb24 ~/checkouts/neon 130 (git: main*)
$ DEBUG=true neonctl auth
DEBUG: Flushing CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Flushed CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Discovering oauth server
DEBUG: Sent CLI error event: UNKNOWN_ERROR
ERROR:
DEBUG: Stack: AggregateError [ECONNREFUSED]:
    at internalConnectMultiple (node:net:1117:18)
    at afterConnectMultiple (node:net:1684:7)
(default) jbo@neon-mb24 ~/checkouts/neon 1 (git: main*)
$ DEBUG=true neonctl auth
DEBUG: Flushing CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Flushed CLI started event with userId: aa0337d5-23ce-473a-b50c-f429cd455989
DEBUG: Discovering oauth server
DEBUG: Listening on port 64886

^ On a 2024 MBP -- first time showed ERROR: and hung, after that a mix of successes and failures. This is easy to repro

$ node --version
v22.1.0
$ neonctl --version
1.29.3

jamesbroadhead avatar May 23 '24 20:05 jamesbroadhead

We discussed the issue with @jamesbroadhead today and could not reproduce it anymore. For better debugging, I have added log statements and error handling when the browser fails to open. The auth URL is displayed in the console, so the user can manually click on it and authenticate.

Additionally, I added a timeout of 60 seconds for the authentication flow.

The new version 1.29.5 has been published to the NPM registry.

Shridhad avatar May 28 '24 11:05 Shridhad

Nothing helpful in the logs. James and the original reporter couldn't reproduce.

Might have been a temporary issue. There are more logs now.

zaynetro avatar Jun 03 '24 14:06 zaynetro

Snowflake Query - https://app.snowflake.com/dzalgeg/ro76690/wOa4k8noI6i#query

Shridhad avatar Jun 03 '24 16:06 Shridhad