twilio / twilio-node

Node.js helper library
MIT License
1.37k stars 495 forks source link

[Feature Request]: twilio message create timeout #1004

Closed kareig closed 1 month ago

kareig commented 4 months ago

Preflight Checklist

Problem Description

Hi,

We have an issue quite often when twilio message create never gets a response and twilio serverless function times out on runtime which has 10s hard limit.

We use v3.29.2.

`

client.messages .create({ body: 'Hello from twilio-node', to: '+12345678901', // Text your number from: '+12345678901', // From a valid Twilio number }) .then((message) => console.log(message.sid));

`

So given the example on such scenario it never proceeds to .then() and twilio serverless function gets runtime timeout.

Twilio support is asking for proof, we do have logging and we clearly see that twilio helper never proceeds to .then(), but that is not enough.

Maybe having an official built-in timeout for .create() would help better, because now we doing axios call to twilio helper instead with timeout of 5s in order to provide some proof of such issue.

Thanks

Proposed Solution

Provide timeout for .create() in order to terminate waiting for the response.

Alternatives Considered

Provide timeout for .create() in order to terminate waiting for the response.

Additional Information

No response

kareig commented 4 months ago

going over source i see there are all the undocumented options i could use and will try them: options

thomas-topway-it commented 3 months ago

hello @kareig , we are having the same problem using it from svelte (vercel) server-side. Finally how have you solved it ?

Here is our import

import TwilioSdk from 'twilio';
const twilio = TwilioSdk(accountSid, authToken, {
  lazyLoading: false,
  autoRetry: true,
  maxRetries: 3,
  logLevel: 'debug',
});
kareig commented 3 months ago

Hi @thomas-topway-it,

Few things solved our issues we had:

1) adding timeout/retry on twilio client:

const twilioClient = context.getTwilioClient({
      autoRetry: true,
      maxRetries: 3,
      maxRetryDelay: 500,
      defaultTimeout: 1000,
    });

2) We also ship logs to external source so we had to set wait timeout for 1s for each callback, otherwise twilio function terminates immediately and no logs shipped to external endpoint:

return setTimeout(() =>
          callback(null, getSuccessResponse("SMS", messageSid), 1000)
        );

3) We also asked to extend timeout on our server-side vendor to wait for 10s from twilio (which is hard limit runtime) and only then timeout but with retries this probably does not make sense anymore.

Mostly timeout/retries for twilio client solved our issues because now we get a proper response from twilio client instantly and it does not hit a hard limit of 10s and runtime does not timeout without any response in case phone number is blocked or combination of twilio sender and receive is not allowed.

tiwarishubham635 commented 1 month ago

Is this still an issue?

thomas-topway-it commented 1 month ago

hello, we have solved with a simple await instruction, apparently the app redirected to a new route before that the request was completed