messagebird / messagebird-nodejs

The open source Node.js client for MessageBird's REST API
https://www.messagebird.com/developers
105 stars 44 forks source link

request failed: socket hang up error #23

Open gjr-qm opened 5 years ago

gjr-qm commented 5 years ago

The last days we get (a lot of) errors while using the client in our production system. Before that everything was working fine.

We're using client version 2.13 and the source of the error is line 93, position 19 in messagebird.js

Anyone else experiencing the same error?

kozmoz commented 4 years ago

Similar issue here right now. 30% of the time "request failed: socket hang up" when loading a list of SMS messages. Was this issue ever resolved? How?

Version: messagebird@3.5.0

juergengunz commented 4 years ago

same issue for me, any idea what is the cause?

kozmoz commented 4 years ago

Similar issue here right now. 30% of the time "request failed: socket hang up" when loading a list of SMS messages. Was this issue ever resolved? How?

Replaced the MessageBird library by Axios and got rid of the MessageBird library completely. This solved my issue. The REST endpoints are really simple ( https://developers.messagebird.com/api/sms-messaging/#list-messages ). To receive the list of messages e.g.:

const axios = require('axios').default;
const MESSAGES_URL = 'https://rest.messagebird.com/messages';

axios.get(MESSAGES_URL, {
            params: {
                // The status of the message.
                // Status scheduled, sent, buffered, delivered, expired, or delivery_failed.
                status: '',
                // The limit of messages to retrieve.
                limit: MAX_NUMBER_OF_MESSAGES,
                // The number of messages to skip before selecting.
                offset: 0
            },
            headers: {'Authorization': `AccessKey ${messageBirdAPIKey}`}
        })
            .then(response => {
                processMessages(response.data.items);
            })
            .catch(function (error) {
                logger.error(`Accessing url "${MESSAGES_URL}" to get sms messages failed: `, error);
            });
schampilomatis commented 3 years ago

This is caused by the 5 seconds timeout that is set in the client. Requests that take longer than 5sec will show this message when timing out, if the default settings are left there.

How to set timeout to 10s:

var messagebird = require('messagebird')('<YOUR_ACCESS_KEY>', 10000); //(value is in milliseconds).
Talha089 commented 3 years ago

so how can we resolved that?