Skip to content

Commit

Permalink
fix: multiple promisified amqp-coffee libs
Browse files Browse the repository at this point in the history
NOTE: when multiple versions of @microfleet/transport-amqp
were included it would cause a crash on startup.
Solved by adding a symbol that tracks promisification and
exits early when we try to do it again
  • Loading branch information
AVVS committed Nov 29, 2019
1 parent 1b7fb18 commit cf6e156
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-mocha": "^6.2.2",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-unicorn": "^13.0.0",
"eslint-plugin-unicorn": "^14.0.0",
"jaeger-client": "^3.17.1",
"microtime": "^3.0.0",
"mocha": "^6.2.2",
Expand All @@ -58,7 +58,7 @@
"dependencies": {
"@hapi/joi": "^16.1.8",
"@microfleet/amqp-coffee": "^1.3.1",
"bluebird": "^3.7.1",
"bluebird": "^3.7.2",
"common-errors": "^1.0.5",
"debug": "^4.1.1",
"eventemitter3": "^4.0.0",
Expand Down
11 changes: 8 additions & 3 deletions src/utils/transport.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const Promise = require('bluebird');

const kPromisified = Symbol.for('@microfleet/amqp-promisified');

// Promisify stuff
['Exchange', 'Queue', 'Connection', 'Consumer', 'Publisher'].forEach((name) => {
const path = require.resolve(`@microfleet/amqp-coffee/bin/src/lib/${name}`);
/* eslint-disable import/no-dynamic-require */
Promise.promisifyAll(require(path).prototype);
/* eslint-enable import/no-dynamic-require */
const mod = require(path); // eslint-disable-line import/no-dynamic-require

if (mod[kPromisified]) return;

Promise.promisifyAll(mod.prototype);
mod[kPromisified] = true;
});

const amqp = require('@microfleet/amqp-coffee');
Expand Down
19 changes: 15 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,11 @@ bluebird@^3.7.1:
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.1.tgz#df70e302b471d7473489acf26a93d63b53f874de"
integrity sha512-DdmyoGCleJnkbp3nkbxTLJ18rjDsE4yCggEwKNXkeV123sPNfOCYeDoeuOY+F2FrSjO1YXcTU+dsy96KMy+gcg==

bluebird@^3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==

bottleneck@^2.18.1:
version "2.19.5"
resolved "https://registry.yarnpkg.com/bottleneck/-/bottleneck-2.19.5.tgz#5df0b90f59fd47656ebe63c78a98419205cadd91"
Expand Down Expand Up @@ -2421,10 +2426,10 @@ eslint-plugin-unicorn@^12.1.0:
safe-regex "^2.0.2"
semver "^6.3.0"

eslint-plugin-unicorn@^13.0.0:
version "13.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-13.0.0.tgz#3d73a17cc34ade1aaa02655ae78bbd8a2053fa81"
integrity sha512-9CQk0v74vQpETMt6iqNgjf3IbWEFhrT0sjaLnjkl9SF3rJH6ZL9f7H42BXJ6LPENQR97QzhrIvB8VG0nD05wxQ==
eslint-plugin-unicorn@^14.0.0:
version "14.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-14.0.0.tgz#ea029443f415fbbf6e68a202d572c91fe483453a"
integrity sha512-hbW0Tl/TixLIpeObsrdYl01XTud3HZzNd705AjUzJCMcQFRc2jmL+IeD7uue/Nw8HaP2qwoWW1LldHxz7XvwVg==
dependencies:
ci-info "^2.0.0"
clean-regexp "^1.0.0"
Expand All @@ -2438,6 +2443,7 @@ eslint-plugin-unicorn@^13.0.0:
lodash.topairs "^4.3.0"
lodash.upperfirst "^4.3.1"
read-pkg-up "^7.0.0"
regexp-tree "^0.1.16"
regexpp "^3.0.0"
reserved-words "^0.1.2"
safe-regex "^2.1.1"
Expand Down Expand Up @@ -6369,6 +6375,11 @@ regex-not@^1.0.0, regex-not@^1.0.2:
extend-shallow "^3.0.2"
safe-regex "^1.1.0"

regexp-tree@^0.1.16:
version "0.1.16"
resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.16.tgz#0715feadb6f766aad7eac5ef4287d2c39acf2fc5"
integrity sha512-nXWhGJLTWLNdhWF1uqoXQgAOgv8mQGpgXTOk8BWp08YMOKCtn74VoyOJ+AXZ68Dj50Myd+msYs+aGRBzWJ5dJA==

regexp-tree@~0.1.1:
version "0.1.14"
resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.14.tgz#1abca3675f6cc4b0dee5c959c6c4554ed172dfae"
Expand Down

0 comments on commit cf6e156

Please sign in to comment.