CartoDB / CartoDB-SQL-API

CartoDB SQL API
BSD 3-Clause "New" or "Revised" License
63 stars 64 forks source link

Fails connecting to database in some requests #535

Closed mondeja closed 6 years ago

mondeja commented 6 years ago

I'm developing an application for a company that uses CartoDB-SQL-API. Seeing logs on CartoDB-SQL-API/logs I've seen that sometimes the SQL API fails producing errors like the next, but almost all queries are working fine:

[2018-08-28 11:53:33.341] [ERROR] console - EXCEPTION REPORT: Error: cannot connect to the database
    at /root/CartoDB-SQL-API/node_modules/cartodb-psql/lib/psql.js:369:23
    at /root/CartoDB-SQL-API/node_modules/cartodb-psql/node_modules/pg/lib/pool.js:64:25
    at /root/CartoDB-SQL-API/node_modules/cartodb-psql/node_modules/pg/node_modules/generic-pool/lib/generic-pool.js:271:11
    at /root/CartoDB-SQL-API/node_modules/cartodb-psql/node_modules/pg/lib/pool.js:27:26
    at null.<anonymous> (/root/CartoDB-SQL-API/node_modules/cartodb-psql/node_modules/pg/lib/client.js:170:9)
    at EventEmitter.emit (events.js:95:17)
    at null.<anonymous> (/root/CartoDB-SQL-API/node_modules/cartodb-psql/node_modules/pg/lib/connection.js:109:12)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:746:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)

Any idea of what's happening?

dgaubert commented 6 years ago

It looks like database's connection params are wrong. The application relies on Redis to get user's connection parameters. You can find here how we get the username from the request.

What version of SQL-API are you running?

mondeja commented 6 years ago

Thanks, is 1.42.7.

dgaubert commented 6 years ago

Please, try to identify the user's request that is throwing that error and check:

$ redis-cli
> select 5
> hgetall rails:users:{username}
1) "database_host"
2) ...

Check the keys database_host, database_name, database_password, and database_publicuser have the right values.

mondeja commented 6 years ago

Thanks you very much for your response. We are implementing our own layer manager, so I've closed this!