twilio-node icon indicating copy to clipboard operation
twilio-node copied to clipboard

Could you replace "q" to Promise es6?

Open rgnevashev opened this issue 8 years ago • 21 comments

rgnevashev avatar Aug 24 '17 15:08 rgnevashev

@rgnevashev Are you having trouble using the q library? We could migrate over to using native promises but haven't had much feedback or other compelling reasons to warrant the work so far. We are certainly open to this if there is enough user demand.

codejudas avatar Aug 24 '17 17:08 codejudas

@efossier yes, I have the issue with q lib. Im using native promise lib and my code doesnt work properly. async/await feature doesnt work as well. I sure, the change to native promise doesnt take much time

rgnevashev avatar Aug 24 '17 19:08 rgnevashev

https://github.com/twilio/twilio-node/blob/master/lib/base/RequestClient.js#L61

rgnevashev avatar Aug 24 '17 19:08 rgnevashev

@rgnevashev ok, I've created a ticket internally to track this work. It may be awhile until we have the bandwidth to pick this up however, do you have a work around you can use in the meantime?

codejudas avatar Aug 24 '17 19:08 codejudas

we get a lot of errors from /app/node_modules/q/q.js:876

davidchl avatar Nov 02 '18 21:11 davidchl

I am having trouble with the same lines as @davidchl. I get an error in the terminal:

Error: Authenticate

kyle-hall avatar Dec 20 '18 04:12 kyle-hall

@efossier Is this something that's still being looked into?

kyle-hall avatar Dec 20 '18 04:12 kyle-hall

Upon further review, I am not having trouble with the q library, itself. I made a mistake when matching up my account sid and auth tokens, and this is why I saw this error. My code is working now, and I can send messages. @davidchl maybe you already checked this, but it might be worth confirming that the account sid and auth token are from your normal account, not the test account. I ran into trouble with the test account, too.

kyle-hall avatar Dec 20 '18 05:12 kyle-hall

@efossier @kyle-hall

Hi all, We've been getting the q errors from reservation.js

Note that we modified the q.js to the catch 2001 errors and not allow it to propagate because it causes our server to restart:

function Promise_rethrow(error) {
        console.log('-----------');
        console.log(error);
        console.log('-----------');

       if (error.code === 20001) { // causes server to restart
        return;
        }

        throw error;
}

Here's the trace:

at Object.opts.done (/app/node_modules/twilio/lib/rest/taskrouter/v1/workspace/task/reservation.js:190:18)
at Pending_become_eachMessage_task (/app/node_modules/q/q.js:1377:30)
at RawTask.call (/app/node_modules/asap/asap.js:40:19)
at Pending_become_eachMessage_task (/app/node_modules/q/q.js:1377:30)
at RawTask.call (/app/node_modules/asap/asap.js:40:19)
at onComplete (/app/node_modules/twilio/lib/rest/taskrouter/v1/workspace/task/reservation.js:110:14)
at Rejected_dispatch [as dispatch] (/app/node_modules/q/q.js:1319:23)
at Promise_done_rejected (/app/node_modules/q/q.js:861:26)
at /app/node_modules/twilio/lib/rest/taskrouter/v1/workspace/task/reservation.js:243:16
at flush (/app/node_modules/asap/raw.js:50:29)
at Promise_done_rejected (/app/node_modules/q/q.js:861:26)
at flush (/app/node_modules/asap/raw.js:50:29)
at process._tickCallback (internal/process/next_tick.js:61:11)
at Promise_then_rejected (/app/node_modules/q/q.js:779:43)
at process._tickCallback (internal/process/next_tick.js:61:11)
at Rejected_then [as then] (/app/node_modules/q/q.js:1331:23)
at Rejected_then [as then] (/app/node_modules/q/q.js:1331:23)
at Deferred.modifiedReject [as reject] (/app/bin/q.ts:15:15)
[object Object]
at Rejected_dispatch [as dispatch] (/app/node_modules/q/q.js:1319:23)
at Promise_then_rejected (/app/node_modules/q/q.js:779:43)
at Deferred.modifiedReject [as reject] (/app/bin/q.ts:15:15)
[object Object]

The q.ts is our file and we just use it for logging the q errors.

Any ideas on what the issue could be?

Thanks, David

davidchl avatar Dec 20 '18 23:12 davidchl

twilio-node constantly gives us UnhandledPromiseRejectionWarning that traces down to q.js. See the stack trace below:

(/app/node_modules/twilio/lib/rest/taskrouter/v1/workspace/task/reservation.js:190:18)
    at onComplete (/app/node_modules/twilio/lib/rest/taskrouter/v1/workspace/task/reservation.js:110:14)
    at Promise_then_rejected (/app/node_modules/q/q.js:779:43)
    at Promise_done_rejected (/app/node_modules/q/q.js:861:26)
    at Rejected_then [as then] (/app/node_modules/q/q.js:1323:23)
    at Rejected_dispatch [as dispatch] (/app/node_modules/q/q.js:1311:23)
    at Pending_become_eachMessage_task (/app/node_modules/q/q.js:1369:30)
    at RawTask.call (/app/node_modules/asap/asap.js:40:19)
    at flush (/app/node_modules/asap/raw.js:50:29)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:54) UnhandledPromiseRejectionWarning
(node:54) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1351)
(node:54) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1351)

From the error description, it sounds like twilio-node is not handling the promise rejection properly. This is causing us a lot of headache please help.

omidkrad avatar Jan 04 '19 20:01 omidkrad

I tried the method described here to get around the issue, but that didn't fix it!

process.on('unhandledRejection', (reason, promise) => {
  logger.error('Unhandled Promise Rejection at:', reason.stack || reason);
});

omidkrad avatar Jan 24 '19 23:01 omidkrad

This is still in the backlog and will require a major version bump and doc updates. More +1s on the issue (not on comments) will help move it up.

childish-sambino avatar Jun 21 '19 20:06 childish-sambino

Is it still open?

gagandeepp avatar Sep 15 '20 05:09 gagandeepp

@gagandeepp Yes, still open. I did a POC for making the switch here: https://github.com/twilio/twilio-node/pull/450

But as mentioned above, this will require a MV bump and we'll probably want to do that with other breaking changes.

childish-sambino avatar Sep 15 '20 15:09 childish-sambino

Even though this would require a MV bump, I'd consider this a security requirement for some of Twilio's customers. The q version & library in use here is about 6 years old and makes use of weak-map which has not been updated in 6 years either. Unmaintained and inactive dependencies impose a severe security risk for some companies.

Any way to accelerate this procedure?

beevelop avatar Oct 13 '20 10:10 beevelop

Bumping this again. Continuing the use of non-native promises indefinitely is going to continue confusing developers and inject unexpected bugs. I respect this being a MV breaking change, but it's been years since native Promises were introduced.

thesmart avatar Feb 07 '21 22:02 thesmart

I just ran into an issue with this as well. Attempting to do await twilioClient.messages.create({...}); resulted in hung code. My workaround was just to abandon the client as all I needed was messaging:

 var response = await axios.post(`https://api.twilio.com/2010-04-01/Accounts/${smsAccountSid}/Messages.json`,   
    `From=${encodeURIComponent(process.env.TWILIO_FROM)}&To=${encodeURIComponent(toNumber)}&Body=${encodeURIComponent(message)}`,
    { 
     auth: {
      username: smsAccountSid,
      password: smsAuthToken
     }
    });
  return response;

danroot avatar Oct 23 '21 16:10 danroot

Also seeing this - my application hangs when doing most twilio API calls. I'm using a pretty standard typescript project on v14 of node and it makes this library unusable for me.

a-r-d avatar Nov 10 '21 22:11 a-r-d

NodeJS has had native support for promises dating back to 2015 and async/await in 2017. Given that I'm not sure why this dependency is still used five years later. Our issue with it is that the q.js library is obscuring our stack traces.

adamduren avatar Jun 27 '22 19:06 adamduren

We're currently working on a 4.0 release candidate that will migrate to async/await promises.

childish-sambino avatar Jun 27 '22 19:06 childish-sambino

@childish-sambino great to hear! Thanks for the update.

adamduren avatar Jun 27 '22 19:06 adamduren

Closing as fixed (lastly) by https://github.com/twilio/twilio-node/pull/826

This will be included in the first release candidate for twilio-node@v4 dropping in a week.

childish-sambino avatar Nov 23 '22 21:11 childish-sambino