galacticcouncil / polkalert

Polkadot / Substrate based node monitoring.
Apache License 2.0
17 stars 8 forks source link

Error when trying to connect to db #23

Closed akhanaton closed 4 years ago

akhanaton commented 4 years ago

Followed the steps in the readme.

When I attempt to start the server I get the following:

error: password authentication failed for user "user"

image

Andkoo commented 4 years ago

Are you trying to start the whole project via the yarn start command or only the server via yarn start:server?

akhanaton commented 4 years ago

I have tried both ways and get the same error:

First Way:

yarn start:db -> yarn start:server - Fails

Second Way

yarn:start - Fails

Both with the same error

jak-pan commented 4 years ago

Can you please try running

yarn stop:db -> yarn start:db , wait till the db finishes starting (ready to accept connections) -> yarn start:server -> yarn start:client

This can very well be the problem, since db crashes with auth error if tables are not created yet. If not, I'll create HotFix branch for you with logging inside db enabled. If yes, I'll catch the error and return some sane error message instead of crashing the server.

The plain yarn start command is not the best way to run the app right now, since it can cause some side effects and you are not controlling what each process does separately.

akhanaton commented 4 years ago

Followed those steps, still the same issue.

jak-pan commented 4 years ago

Can you paste both full logs of terminals running db and the server app?

akhanaton commented 4 years ago

starting db...

λ yarn start:db
yarn run v1.16.0
$ cd packages/server && docker-compose up --build
Creating network "server_default" with the default driver
Creating monitor-db ... done
Attaching to monitor-db
monitor-db | The files belonging to this database system will be owned by user "postgres".
monitor-db | This user must also own the server process.
monitor-db |
monitor-db | The database cluster will be initialized with locale "en_US.utf8".
monitor-db | The default database encoding has accordingly been set to "UTF8".
monitor-db | The default text search configuration will be set to "english".
monitor-db |
monitor-db | Data page checksums are disabled.
monitor-db |
monitor-db | fixing permissions on existing directory /var/lib/postgresql/data ... ok
monitor-db | creating subdirectories ... ok
monitor-db | selecting default max_connections ... 100
monitor-db | selecting default shared_buffers ... 128MB
monitor-db | selecting default timezone ... Etc/UTC
monitor-db | selecting dynamic shared memory implementation ... posix
monitor-db | creating configuration files ... ok
monitor-db | running bootstrap script ... ok
monitor-db | performing post-bootstrap initialization ... ok
monitor-db | syncing data to disk ...
monitor-db | WARNING: enabling "trust" authentication for local connections
monitor-db | You can change this by editing pg_hba.conf or using the option -A, or
monitor-db | --auth-local and --auth-host, the next time you run initdb.
monitor-db | ok
monitor-db |
monitor-db | Success. You can now start the database server using:
monitor-db |
monitor-db | pg_ctl -D /var/lib/postgresql/data -l logfile start
monitor-db |
monitor-db | waiting for server to start....2019-11-21 05:30:53.836 UTC [41] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
monitor-db | 2019-11-21 05:30:53.853 UTC [42] LOG: database system was shut down at 2019-11-21 05:30:53 UTC
monitor-db | 2019-11-21 05:30:53.859 UTC [41] LOG: database system is ready to accept connections
monitor-db | done
monitor-db | server started
monitor-db | CREATE DATABASE
monitor-db |
monitor-db |
monitor-db | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
monitor-db |
monitor-db | 2019-11-21 05:30:54.218 UTC [41] LOG: received fast shutdown request
monitor-db | waiting for server to shut down....2019-11-21 05:30:54.221 UTC [41] LOG: aborting any active transactions
monitor-db | 2019-11-21 05:30:54.223 UTC [41] LOG: background worker "logical replication launcher" (PID 48) exited with exit code 1
monitor-db | 2019-11-21 05:30:54.223 UTC [43] LOG: shutting down
monitor-db | 2019-11-21 05:30:54.242 UTC [41] LOG: database system is shut down
monitor-db | done
monitor-db | server stopped
monitor-db |
monitor-db | PostgreSQL init process complete; ready for start up.
monitor-db | monitor-db | 2019-11-21 05:30:54.328 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 monitor-db | 2019-11-21 05:30:54.328 UTC [1] LOG: listening on IPv6 address "::", port 5432 monitor-db | 2019-11-21 05:30:54.337 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" monitor-db | 2019-11-21 05:30:54.357 UTC [59] LOG: database system was shut down at 2019-11-21 05:30:54 UTC monitor-db | 2019-11-21 05:30:54.363 UTC [1] LOG: database system is ready to accept connections

starting server.....

λ yarn start:server yarn run v1.16.0 $ cd packages/server && yarn start $ nodemon src/index.ts [nodemon] 1.19.3 [nodemon] reading config .\nodemon.json [nodemon] to restart at any time, enter rs [nodemon] or send SIGHUP to 201492 to restart [nodemon] ignoring: src/*/.spec.ts [nodemon] watching dir(s): src*\.ts [nodemon] watching extensions: ts,json [nodemon] starting node --inspect=0.0.0.0:9229 --nolazy -r ts-node/register src/index.ts [nodemon] spawning [nodemon] child pid: 197916 [nodemon] watching 19 files Debugger listening on ws://0.0.0.0:9229/670fe0c9-b5fe-4e6c-910e-499691dd52ad For help, see: https://nodejs.org/en/docs/inspector { error: password authentication failed for user "user" at Connection.parseE (D:\projects\polkalert\packages\server\node_modules\pg\lib\connection.js:604:11) at Connection.parseMessage (D:\projects\polkalert\packages\server\node_modules\pg\lib\connection.js:401:19) at Socket. (D:\projects\polkalert\packages\server\node_modules\pg\lib\connection.js:121:22) at Socket.emit (events.js:198:13) at addChunk (_stream_readable.js:288:12) at readableAddChunk (_stream_readable.js:269:11) at Socket.Readable.push (_stream_readable.js:224:10) at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) name: 'error', length: 159, severity: 'FATAL', code: '28P01', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'd:\pginstaller.auto\postgres.windows-x64\src\backend\libpq\auth.c', line: '336', routine: 'auth_failed' } error detected Error: Cannot create connection to database at Object. (D:\projects\polkalert\packages\server\src\db\index.ts:60:11) at Generator.next () at fulfilled (D:\projects\polkalert\packages\server\src\db\index.ts:5:58) at process._tickCallback (internal/process/next_tick.js:68:7) [nodemon] clean exit - waiting for changes before restart

jak-pan commented 4 years ago

Okay, I don't see that you are trying to connect to DB in the log, that's strange. Did you paste it before or after you tried to connect?

I have an idea...

Please pull and checkout to branch hotfix/docker -> stop everything and yarn remove:db then yarn start:db and yarn start:server

akhanaton commented 4 years ago

I copy and pasted after trying to connect.

Again I am getting the same error:

db:

λ yarn start:db
yarn run v1.16.0
$ cd packages/server && docker-compose up --build
Creating network "server_default" with the default driver
Creating monitor-db ... done
Attaching to monitor-db
monitor-db | The files belonging to this database system will be owned by user "postgres".
monitor-db | This user must also own the server process.
monitor-db |
monitor-db | The database cluster will be initialized with locale "en_US.utf8".
monitor-db | The default database encoding has accordingly been set to "UTF8".
monitor-db | The default text search configuration will be set to "english".
monitor-db |
monitor-db | Data page checksums are disabled.
monitor-db |
monitor-db | fixing permissions on existing directory /var/lib/postgresql/data ... ok
monitor-db | creating subdirectories ... ok
monitor-db | selecting default max_connections ... 100
monitor-db | selecting default shared_buffers ... 128MB
monitor-db | selecting default timezone ... Etc/UTC
monitor-db | selecting dynamic shared memory implementation ... posix
monitor-db | creating configuration files ... ok
monitor-db | running bootstrap script ... ok
monitor-db | performing post-bootstrap initialization ... ok
monitor-db | syncing data to disk ...
monitor-db | WARNING: enabling "trust" authentication for local connections
monitor-db | You can change this by editing pg_hba.conf or using the option -A, or
monitor-db | --auth-local and --auth-host, the next time you run initdb.
monitor-db | ok
monitor-db |
monitor-db | Success. You can now start the database server using:
monitor-db |
monitor-db | pg_ctl -D /var/lib/postgresql/data -l logfile start
monitor-db |
monitor-db | waiting for server to start....2019-11-21 13:11:14.543 UTC [41] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
monitor-db | 2019-11-21 13:11:14.562 UTC [42] LOG: database system was shut down at 2019-11-21 13:11:14 UTC
monitor-db | 2019-11-21 13:11:14.568 UTC [41] LOG: database system is ready to accept connections
monitor-db | done
monitor-db | server started
monitor-db | CREATE DATABASE
monitor-db |
monitor-db |
monitor-db | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
monitor-db |
monitor-db | waiting for server to shut down...2019-11-21 13:11:14.946 UTC [41] LOG: received fast shutdown request
monitor-db | .2019-11-21 13:11:14.950 UTC [41] LOG: aborting any active transactions
monitor-db | 2019-11-21 13:11:14.952 UTC [41] LOG: background worker "logical replication launcher" (PID 48) exited with exit code 1
monitor-db | 2019-11-21 13:11:14.953 UTC [43] LOG: shutting down
monitor-db | 2019-11-21 13:11:14.973 UTC [41] LOG: database system is shut down
monitor-db | done
monitor-db | server stopped
monitor-db |
monitor-db | PostgreSQL init process complete; ready for start up.
monitor-db |
monitor-db | 2019-11-21 13:11:15.058 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
monitor-db | 2019-11-21 13:11:15.058 UTC [1] LOG: listening on IPv6 address "::", port 5432
monitor-db | 2019-11-21 13:11:15.067 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
monitor-db | 2019-11-21 13:11:15.086 UTC [59] LOG: database system was shut down at 2019-11-21 13:11:14 UTC
monitor-db | 2019-11-21 13:11:15.093 UTC [1] LOG: database system is ready to accept connections

server:

λ yarn start:server
yarn run v1.16.0
$ cd packages/server && yarn start
$ nodemon src/index.ts
[nodemon] 1.19.3
[nodemon] reading config .\nodemon.json
[nodemon] to restart at any time, enter rs
[nodemon] or send SIGHUP to 212424 to restart
[nodemon] ignoring: src/*/.spec.ts
[nodemon] watching dir(s): src*\.ts
[nodemon] watching extensions: ts,json
[nodemon] starting node --inspect=0.0.0.0:9229 --nolazy -r ts-node/register src/index.ts
[nodemon] spawning
[nodemon] child pid: 212080
[nodemon] watching 14 files
Debugger listening on ws://0.0.0.0:9229/ce538008-b4bd-480d-8699-b8a71e68635a
For help, see: https://nodejs.org/en/docs/inspector
{ error: password authentication failed for user "polkaDbUser"
at Connection.parseE (D:\projects\polkalert\packages\server\node_modules\pg\lib\connection.js:604:11)
at Connection.parseMessage (D:\projects\polkalert\packages\server\node_modules\pg\lib\connection.js:401:19)
at Socket. (D:\projects\polkalert\packages\server\node_modules\pg\lib\connection.js:121:22)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
name: 'error',
length: 166,
severity: 'FATAL',
code: '28P01',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file:
'd:\pginstaller.auto\postgres.windows-x64\src\backend\libpq\auth.c',
line: '336',
routine: 'auth_failed' }
error detected Error: Cannot create connection to database
at Object. (D:\projects\polkalert\packages\server\src\db\index.ts:60:11)
at Generator.next ()
at fulfilled (D:\projects\polkalert\packages\server\src\db\index.ts:5:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
[nodemon] clean exit - waiting for changes before restart

jak-pan commented 4 years ago

Ok so it looks like you’re not being connected to our postgres database. To confirm that please yarn:stop:db -> curl localhost:5432 If it returns anything other than error (i.e. empty response) you are running another instance of postgres or some other service on 5432 - in that case. Please checkout to dev branch —> yarn -> yarn:setup and change the port of postgres database to something else i.e 5433 then try again running yarn start:db -> yarn start:server

akhanaton commented 4 years ago

Yup, you are correct. I completely forgot I had a local instance running. Sorry about that.

jak-pan commented 4 years ago

No problem. I didn't expect that, since on OSX, docker crashes if it can't register port for container. We're smarter now. I'll try to patch this later. Thanks for debugging.