Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace instanceof Promise checks with thennable checks #114

Merged
merged 1 commit into from
Apr 19, 2019

Conversation

M-TGH
Copy link
Contributor

@M-TGH M-TGH commented Apr 18, 2019

Issue #, if available: No issue, came up in #98 (comment).

Description of changes: Replaces 2 instanceof Promise checks to instead check if .then is a function.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

If preferred I can merge this into the feat/support-pool-get-connection branch.

Wasn't too sure on a way to add tests for this, so refrained on adding them for now. Let me know if you have any ideas.

Copy link
Contributor

@chrisradek chrisradek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, if the existing tests pass I'm fine with merging. This change is more to protect us in case mysql supports providing a customer Promise implementation in the future (if it doesn't already).

@chrisradek
Copy link
Contributor

@M-TGH
Thank you for the contribution! Merging!

@chrisradek chrisradek merged commit cc57839 into aws:master Apr 19, 2019
@darcoli
Copy link

darcoli commented Apr 22, 2019

We seem to be hitting a situation where connection is undefined and then everything else fails because now all conditions in the if statements try to read property then of undefined. I believe there should be an additional guard for such cases in all places where this was changed. (We incurred this issue with typeorm and mysql with aws-xray-sdk 2.3.1 within aws lambda)

Full exception:

TypeError: Cannot read property 'then' of undefined
  File "/var/task/dist/handler.js", line 89720, col 16, in Pool.patchedGetConnection [as getConnection]
    if (result.then instanceof Function) return result.then(patchObject);
  File "/var/task/dist/handler.js", line 5255, col 18, in null.<anonymous>
    pool.getConnection(function (err, connection) {
  File "/var/task/dist/handler.js", line 81363, col 18, in new WrappedPromise
    executor.apply(context, args);
  File "/var/task/dist/handler.js", line 5252, col 16, in MysqlDriver.module.exports.MysqlDriver.createPool
    return new Promise(function (ok, fail) {
  File "/var/task/dist/handler.js", line 4765, col 51, in MysqlDriver.<anonymous>
    return [4 /*yield*/, this.createPool(this.createConnectionOptions(this.options, this.options))];
  File "/var/task/dist/handler.js", line 209, col 23, in step
    op = body.call(thisArg, _);
  File "/var/task/dist/handler.js", line 190, col 53, in Object.next
    function verb(n) { return function (v) { return step([n, v]); }; }
  File "/var/task/dist/handler.js", line 183, col 71, in null.<anonymous>
    step((generator = generator.apply(thisArg, _arguments || [])).next());
  File "/var/task/dist/handler.js", line 81363, col 18, in new WrappedPromise
    executor.apply(context, args);
  File "/var/task/dist/handler.js", line 179, col 12, in Module.__awaiter
    return new (P || (P = Promise))(function (resolve, reject) {
  File "/var/task/dist/handler.js", line 4750, col 24, in MysqlDriver.module.exports.MysqlDriver.connect
    return tslib_1.__awaiter(this, void 0, void 0, function () {
  File "/var/task/dist/handler.js", line 43526, col 58, in Connection.<anonymous>
    return [4 /*yield*/, this.driver.connect()];
  File "/var/task/dist/handler.js", line 209, col 23, in step
    op = body.call(thisArg, _);
  File "/var/task/dist/handler.js", line 190, col 53, in Object.next
    function verb(n) { return function (v) { return step([n, v]); }; }
  File "/var/task/dist/handler.js", line 183, col 71, in null.<anonymous>
    step((generator = generator.apply(thisArg, _arguments || [])).next());
  File "/var/task/dist/handler.js", line 81363, col 18, in new WrappedPromise
    executor.apply(context, args);
  File "/var/task/dist/handler.js", line 179, col 12, in Module.__awaiter
    return new (P || (P = Promise))(function (resolve, reject) {
  File "/var/task/dist/handler.js", line 43518, col 24, in Connection.module.exports.Connection.connect
    return tslib_1.__awaiter(this, void 0, void 0, function () {
  File "/var/task/dist/handler.js", line 155846, col 65, in ConnectionManager.get
    return connection.isConnected ? connection : connection.connect();
  File "/var/task/dist/handler.js", line 155960, col 57, in CommandScheduleService.runScheduledCommands
    const connection = await this.connectionManager.get();
  File "/var/task/dist/handler.js", line 56480, col 27, in module.exports.exports.commandScheduleRunner.handler_1.sentryfy
    await scheduleService.runScheduledCommands();
  File "/var/task/dist/handler.js", line 42585, col 25, in null.<anonymous>
    const promise = handler(event, context, callback);

@chrisradek
Copy link
Contributor

@darcoli
Thank you for reporting that issue. I'll create an update those conditions to include an existence check before checking for then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants