citizenos / citizenos-api

Citizen OS API application - https://api.citizenos.com/
Other
31 stars 7 forks source link

App crashes when DATABASE_OPTIONS_POOL_MAX environment variable is set #137

Closed tiblu closed 4 years ago

tiblu commented 5 years ago

What is the problem?

App crashes when DATABASE_OPTIONS_POOL_MAX environment variable is set. This happens after upgrading Sequelize. The latest version has a sanity check that will verify that pool size parameters are of integer type, but every variable coming from ENV is a string.

04 Jun 2019 08:51:18.486152 <190>1 2019-06-04T08:51:17.575449+00:00 host app web.1 - [2019-06-04T08:51:17.571] [INFO] default - Sequelize connection configuration { url:
04 Jun 2019 08:51:18.572156 <190>1 2019-06-04T08:51:17.575474+00:00 host app web.1 - 'postgres://*****:*****@*******:5432/*****',
04 Jun 2019 08:51:18.57268 <190>1 2019-06-04T08:51:17.575477+00:00 host app web.1 - options:
04 Jun 2019 08:51:18.57283 <190>1 2019-06-04T08:51:17.575478+00:00 host app web.1 - { dialect: 'postgres',
04 Jun 2019 08:51:18.572107 <190>1 2019-06-04T08:51:17.575480+00:00 host app web.1 - logging: [Function: defaultLoggingFunction],
04 Jun 2019 08:51:18.57279 <190>1 2019-06-04T08:51:17.575481+00:00 host app web.1 - benchmark: true,
04 Jun 2019 08:51:18.572130 <190>1 2019-06-04T08:51:17.575483+00:00 host app web.1 - sync: { force: true, logging: [Function: defaultLoggingFunction] },
04 Jun 2019 08:51:18.57270 <190>1 2019-06-04T08:51:17.575484+00:00 host app web.1 - define:
04 Jun 2019 08:51:18.57285 <190>1 2019-06-04T08:51:17.575485+00:00 host app web.1 - { underscored: false,
04 Jun 2019 08:51:18.57289 <190>1 2019-06-04T08:51:17.575487+00:00 host app web.1 - freezeTableName: false,
04 Jun 2019 08:51:18.57290 <190>1 2019-06-04T08:51:17.575489+00:00 host app web.1 - syncOnAssociation: true,
04 Jun 2019 08:51:18.57282 <190>1 2019-06-04T08:51:17.575490+00:00 host app web.1 - charset: 'utf8',
04 Jun 2019 08:51:18.57293 <190>1 2019-06-04T08:51:17.575492+00:00 host app web.1 - collate: 'utf8_general_ci',
04 Jun 2019 08:51:18.57283 <190>1 2019-06-04T08:51:17.575493+00:00 host app web.1 - timestamps: true,
04 Jun 2019 08:51:18.57283 <190>1 2019-06-04T08:51:17.575494+00:00 host app web.1 - paranoid: true },
04 Jun 2019 08:51:18.57279 <190>1 2019-06-04T08:51:17.575495+00:00 host app web.1 - omitNull: false,
04 Jun 2019 08:51:18.57293 <190>1 2019-06-04T08:51:17.575496+00:00 host app web.1 - dialectOptions: { ssl: true },
04 Jun 2019 08:51:18.572116 <190>1 2019-06-04T08:51:17.575498+00:00 host app web.1 - pool: { min: 0, max: '10', idle: 5000, evict: 5000 },
04 Jun 2019 08:51:18.57296 <190>1 2019-06-04T08:51:17.575506+00:00 host app web.1 - isolationLevel: 'READ COMMITTED',
04 Jun 2019 08:51:18.57283 <190>1 2019-06-04T08:51:17.575508+00:00 host app web.1 - username: undefined,
04 Jun 2019 08:51:18.57286 <190>1 2019-06-04T08:51:17.575509+00:00 host app web.1 - password: undefined } }
04 Jun 2019 08:51:18.572105 <190>1 2019-06-04T08:51:17.648024+00:00 host app web.1 - /app/node_modules/sequelize-pool/lib/Pool.js:71
04 Jun 2019 08:51:18.572110 <190>1 2019-06-04T08:51:17.648027+00:00 host app web.1 - throw new Error("max must be an integer > 0");
04 Jun 2019 08:51:18.57265 <190>1 2019-06-04T08:51:17.648029+00:00 host app web.1 - ^
04 Jun 2019 08:51:18.57258 <190>1 2019-06-04T08:51:17.648030+00:00 host app web.1 -
04 Jun 2019 08:51:18.57291 <190>1 2019-06-04T08:51:17.648031+00:00 host app web.1 - Error: max must be an integer > 0
04 Jun 2019 08:51:18.572126 <190>1 2019-06-04T08:51:17.648033+00:00 host app web.1 - at new Pool (/app/node_modules/sequelize-pool/lib/Pool.js:71:13)
04 Jun 2019 08:51:18.572173 <190>1 2019-06-04T08:51:17.648034+00:00 host app web.1 - at ConnectionManager.initPools (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:127:19)
04 Jun 2019 08:51:18.572166 <190>1 2019-06-04T08:51:17.648036+00:00 host app web.1 - at new ConnectionManager (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:42:10)
04 Jun 2019 08:51:18.572165 <190>1 2019-06-04T08:51:17.648037+00:00 host app web.1 - at new ConnectionManager (/app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:16:5)
04 Jun 2019 08:51:18.572151 <190>1 2019-06-04T08:51:17.648038+00:00 host app web.1 - at new PostgresDialect (/app/node_modules/sequelize/lib/dialects/postgres/index.js:14:30)
04 Jun 2019 08:51:18.572132 <190>1 2019-06-04T08:51:17.648040+00:00 host app web.1 - at new Sequelize (/app/node_modules/sequelize/lib/sequelize.js:320:20)
04 Jun 2019 08:51:18.572115 <190>1 2019-06-04T08:51:17.648041+00:00 host app web.1 - at Object.<anonymous> (/app/db/models/index.js:50:17)
04 Jun 2019 08:51:18.572120 <190>1 2019-06-04T08:51:17.648042+00:00 host app web.1 - at Module._compile (internal/modules/cjs/loader.js:688:30)
04 Jun 2019 08:51:18.572134 <190>1 2019-06-04T08:51:17.648044+00:00 host app web.1 - at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
04 Jun 2019 08:51:18.572116 <190>1 2019-06-04T08:51:17.648047+00:00 host app web.1 - at Module.load (internal/modules/cjs/loader.js:598:32)
04 Jun 2019 08:51:18.572118 <190>1 2019-06-04T08:51:17.648049+00:00 host app web.1 - at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
04 Jun 2019 08:51:18.572125 <190>1 2019-06-04T08:51:17.648050+00:00 host app web.1 - at Function.Module._load (internal/modules/cjs/loader.js:529:3)
04 Jun 2019 08:51:18.572119 <190>1 2019-06-04T08:51:17.648051+00:00 host app web.1 - at Module.require (internal/modules/cjs/loader.js:636:17)
04 Jun 2019 08:51:18.572112 <190>1 2019-06-04T08:51:17.648053+00:00 host app web.1 - at require (internal/modules/cjs/helpers.js:20:18)
04 Jun 2019 08:51:18.572103 <190>1 2019-06-04T08:51:17.648054+00:00 host app web.1 - at Object.<anonymous> (/app/app.js:10:14)
04 Jun 2019 08:51:18.572120 <190>1 2019-06-04T08:51:17.648055+00:00 host app web.1 - at Module._compile (internal/modules/cjs/loader.js:688:30)
04 Jun 2019 08:51:18.572134 <190>1 2019-06-04T08:51:17.648057+00:00 host app web.1 - at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
04 Jun 2019 08:51:18.572116 <190>1 2019-06-04T08:51:17.648058+00:00 host app web.1 - at Module.load (internal/modules/cjs/loader.js:598:32)
04 Jun 2019 08:51:18.572118 <190>1 2019-06-04T08:51:17.648059+00:00 host app web.1 - at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
04 Jun 2019 08:51:18.572125 <190>1 2019-06-04T08:51:17.648061+00:00 host app web.1 - at Function.Module._load (internal/modules/cjs/loader.js:529:3)
04 Jun 2019 08:51:18.572119 <190>1 2019-06-04T08:51:17.648062+00:00 host app web.1 - at Module.require (internal/modules/cjs/loader.js:636:17)
04 Jun 2019 08:51:18.572112 <190>1 2019-06-04T08:51:17.648063+00:00 host app web.1 - at require (internal/modules/cjs/helpers.js:20:18)
04 Jun 2019 08:51:18.572103 <190>1 2019-06-04T08:51:17.648064+00:00 host app web.1 - at Object.<anonymous> (/app/bin/www:8:11)
04 Jun 2019 08:51:18.572120 <190>1 2019-06-04T08:51:17.648066+00:00 host app web.1 - at Module._compile (internal/modules/cjs/loader.js:688:30)
04 Jun 2019 08:51:18.572134 <190>1 2019-06-04T08:51:17.648067+00:00 host app web.1 - at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
04 Jun 2019 08:51:18.572116 <190>1 2019-06-04T08:51:17.648068+00:00 host app web.1 - at Module.load (internal/modules/cjs/loader.js:598:32)
04 Jun 2019 08:51:18.572118 <190>1 2019-06-04T08:51:17.648069+00:00 host app web.1 - at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
04 Jun 2019 08:51:18.572125 <190>1 2019-06-04T08:51:17.648071+00:00 host app web.1 - at Function.Module._load (internal/modules/cjs/loader.js:529:3)

Possible solution.

Possible solutions:

tiblu commented 5 years ago

Blocked by https://github.com/sequelize/sequelize-pool/pull/4. Also after the PR gets merged, needs Sequelize to update their dependency.

tiblu commented 5 years ago

NOTE: Short term solution has already been implemented

DONE: - Make piece of code that converts the DATABASE_OPTIONS_POOL_MAX to integer before passing on to Sequelize` (53048a0)

KatiVellak commented 4 years ago

Legally reviewed, no impact.

loorm commented 4 years ago

@tiblu Do we need to keep this issue open?

tiblu commented 4 years ago

@loorm Still blocked by https://github.com/sequelize/sequelize-pool/pull/4. BUT, we have a workaround and it's working, thus I'll close this issue.

gallivangames commented 3 years ago

had to parse to int for max and min