ewelink-api icon indicating copy to clipboard operation
ewelink-api copied to clipboard

Slow api, ETIMEDOUT, ECONRESET, ECONNREFUSED

Open Mr-KoKa opened this issue 1 year ago • 14 comments

const ewelink = require('ewelink-api');

(async () => {
  let start = Date.now();
  const connection = new ewelink({
    email: '...',
    password: '...',
    region: 'eu',
  });
  console.log('connection', (Date.now() - start) / 1000);

  try {
    /* get all devices */
    start = Date.now();
    const devices = await connection.getDevices();
    console.log('devices', (Date.now() - start) / 1000);

    /* get specific devide info */
    start = Date.now();
    const device = await connection.getDevice('...');
    console.log('device', (Date.now() - start) / 1000);

    console.log('end');
  } catch(e){
    console.log('exception', (Date.now() - start) / 1000);
    console.log(e);
  }
})();

Above code results in wide range of connection errors:

\...\_ewelink-test>node test.js
connection 0

\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505
                        reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
                               ^
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/login failed, reason: connect ECONNREFUSED 52.57.118.192:8080
    at ClientRequest.<anonymous> (\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505:11)
    at ClientRequest.emit (node:events:527:28)
    at TLSSocket.socketErrorListener (node:_http_client:454:9)
    at TLSSocket.emit (node:events:527:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  type: 'system',
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED'
}

\...\_ewelink-test>node test.js
connection 1

\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505
                        reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
                               ^
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/device?lang=en&appid=...&ts=1677441318&version=8&getTags=1 failed, reason: read ECONNRESET
    at ClientRequest.<anonymous> (\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505:11)
    at ClientRequest.emit (node:events:527:28)
    at TLSSocket.socketErrorListener (node:_http_client:454:9)
    at TLSSocket.emit (node:events:527:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET'
}

\...\_ewelink-test>node test.js
connection 0
exception 17.593
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/login failed, reason: connect ECONNREFUSED 52.57.118.192:8080
    at ClientRequest.<anonymous> (\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505:11)
    at ClientRequest.emit (node:events:527:28)
    at TLSSocket.socketErrorListener (node:_http_client:454:9)
    at TLSSocket.emit (node:events:527:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  type: 'system',
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED'
}

\...\_ewelink-test>node test.js
connection 0
exception 68.915
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/login failed, reason: read ECONNRESET
    at ClientRequest.<anonymous> (\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505:11)
    at ClientRequest.emit (node:events:527:28)
    at TLSSocket.socketErrorListener (node:_http_client:454:9)
    at TLSSocket.emit (node:events:527:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET'
}

\...\_ewelink-test>node test.js
connection 0
exception 168.683
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/login failed, reason: read ECONNRESET
    at ClientRequest.<anonymous> (\...\_ewelink-test\node_modules\node-fetch\lib\index.js:1505:11)
    at ClientRequest.emit (node:events:527:28)
    at TLSSocket.socketErrorListener (node:_http_client:454:9)
    at TLSSocket.emit (node:events:527:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET'
}

Pinging the IP of the endpoint works.

Running the same code on linux server does work most of the time but the times of execution are unacceptable:

# node test.js
connection 0
devices 28.744
device 11.362
end
# node test.js
connection 0
devices 88.173
device 13.592
end
# node test.js
connection 0.001
exception 172.009
FetchError: request to https://eu-api.coolkit.cc:8080/api/user/device?lang=en&appid=...&ts=1677442551&version=8&getTags=1 failed, reason: connect ETIMEDOUT 52.57.118.192:8080
    at ClientRequest.<anonymous> (/root/_/ewelink-test/node_modules/node-fetch/lib/index.js:1505:11)
    at ClientRequest.emit (node:events:378:20)
    at TLSSocket.socketErrorListener (node:_http_client:462:9)
    at TLSSocket.emit (node:events:378:20)
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:81:21) {
  type: 'system',
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT'
}

It was working good before, it started to malfunction about 2 days ago so ~ 2023-02-24

Mr-KoKa avatar Feb 26 '23 20:02 Mr-KoKa

Same here. Stopped working 1-2 days ago. If anyone has a clue how to fix it it would be great. In the meanwhile you can consider switching to webhooks. A little bit cumbersome to setup with ewelink web (scenes) but works until there is a bugfix, unless you need to read out states.

Aristomastrosi avatar Feb 26 '23 20:02 Aristomastrosi

Same problem!

evikhorev avatar Feb 27 '23 06:02 evikhorev

Same issue (not a surprise ... the same enpoint). What is a kind of surprise - the websocket callbacks work still well.

javcz avatar Feb 27 '23 07:02 javcz

Same Problem, where I can report this issued=?

apadilla83 avatar Feb 27 '23 08:02 apadilla83

Same problem here :(

paliuca avatar Feb 27 '23 08:02 paliuca

Seems like https://eu-api.coolkit.cc:8080 is not responding (or very inconsistently).

The 'us' server is responding, but cannot be used with EU ewelink accounts...

pebs74 avatar Feb 27 '23 12:02 pebs74

There are talks on the eWeLink Telegram group about how their server may have been overloaded, maybe an accidental DDoS through someone's bad code, who knows. I can get a login every now and then, but then as soon as you try do anything it seems the authentication is now broken as well. So I keep getting a { error: 406, msg: 'Authentication failed' } response using this package, the Postman response below shows it's not accepting the Bearer token anymore.

Screenshot 2023-02-27 154039

pj-est avatar Feb 27 '23 13:02 pj-est

I also believe the accidental DoS is a likely explanation. That answers why the websocket interface still works well ... without any delay. Btw the status of the "main" control API is not consistent, a while ago it worked well. At this moment it still works but slow (~20 sec delay).

javcz avatar Feb 27 '23 13:02 javcz

Interestingly the mobile app and web portal are triggering my relays instantly. Apparently the API this package uses is not officially supported by eWeLink, so I don't think we can count on a quick resolution from them here. Busy fishing around the web portal to see if there's anything I can grab onto there.

pj-est avatar Feb 27 '23 14:02 pj-est

FYI https://coolkit-technologies.github.io/eWeLink-API/#/en/PlatformOverview

pj-est avatar Feb 27 '23 14:02 pj-est

Has anyone tested branch 4.0.0 already? IDK if it's worth spending time testing it

bartoszpijet avatar Feb 27 '23 17:02 bartoszpijet

Has anyone tested branch 4.0.0 already? IDK if it's worth spending time testing it

It's not an issue of this library, its a problem on eweLink's server, so you can't fix it by changing to any version of this library here.

Hopefully it will be back soon. The https://eu-api.coolkit.cc:8080 response went from 503 to the OpenResty default page already, so they are working on it.

tarres avatar Feb 27 '23 17:02 tarres

Has anyone tested branch 4.0.0 already? IDK if it's worth spending time testing it

It's not an issue of this library, its a problem on eweLink's server, so you can't fix it by changing to any version of this library here.

Hopefully it will be back soon. The https://eu-api.coolkit.cc:8080 response went from 503 to the OpenResty default page already, so they are working on it.

Just noticed that this branch changes API addresses and uses V2, maybe it uses different routes on load balancers and works, just didn't have time to test it

bartoszpijet avatar Feb 27 '23 22:02 bartoszpijet

I just testing th api now, and its works fine without delay, seems solved now!!!. 3 days to solved this, is too much.... There are other way to control ewelink devices? Sonoff zero in lan does not work correctly in certain situations with 2 canal devices.. there is some documentation to work with the devices on lan? without this api?

apadilla83 avatar Feb 28 '23 08:02 apadilla83