A
A
alexdora2016-07-05 22:00:33
In contact with
alexdora, 2016-07-05 22:00:33

How to fix this error in NODEJS websockets?

Connected module https://github.com/TooTallNate/node-socks-proxy-agent . Despite the fact that it says Build Status Failing, the module works properly on wss
Here is the error that stops the script. I need the script to keep running:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Connection Timed Out
    at Socket.onTimeout (/home/admin/web/*/public_html/node_modules/socks-proxy-agent/node_modules/socks/lib/socks-client.js:55:20)
    at Socket.g (events.js:180:16)
    at Socket.EventEmitter.emit (events.js:92:17)
    at Socket._onTimeout (net.js:327:8)
    at Timer.unrefTimeout [as ontimeout] (timers.js:412:13)

Here are the same lines from socks-client.js:55 (finish(new Error 55 line))
exports.createConnection = function (options, callback) {
        var socket = new net.Socket(), finished = false, buff = new SmartBuffer();

        // Defaults
        options.timeout = options.timeout || 10000;
        options.proxy.command = commandFromString(options.proxy.command);
        options.proxy.userid = options.proxy.userid || "";

        var auth = options.proxy.authentication || {};
        auth.username = auth.username || "";
        auth.password = auth.password || "";

        options.proxy.authentication = auth;

        // Connect & negotiation timeout
        function onTimeout() {
            finish(new Error("Connection Timed Out"), socket, null, callback);
        }
        socket.setTimeout(options.timeout, onTimeout);

        // Socket events
        socket.once('close', function () {
            finish(new Error("Socket Closed"), socket, null, callback);
        });

        socket.once('error', function (err) {
        });

Here you need to read slowly:
Since there are a lot of connections in WS (700 connections through different socks proxy servers), there will certainly be a timeout error somewhere. At first the same error fell out at ws.on close. I recreated (did a reconnect). I removed it by recreating the agent object itself from socks-proxy-agent and it disappeared. Dropped out again at the moment when I started to raise more than 700 compounds. At random, I came to the conclusion that one of the socks proxy simply did not respond in timeout. But in the end, the whole script stops.
ADD:
When changing timeout to 100000 (100 seconds as I understand it)
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: socket hang up
    at SecurePair.error (tls.js:1013:23)
    at EncryptedStream.CryptoStream._done (tls.js:705:22)
    at CleartextStream.read [as _read] (tls.js:496:24)
    at CleartextStream.Readable.read (_stream_readable.js:320:10)
    at EncryptedStream.onCryptoStreamFinish (tls.js:301:47)
    at EncryptedStream.g (events.js:180:16)
    at EncryptedStream.EventEmitter.emit (events.js:92:17)
    at finishMaybe (_stream_writable.js:356:12)
    at endWritable (_stream_writable.js:363:3)
    at EncryptedStream.Writable.end (_stream_writable.js:341:5)

ADD2:
I found the file at: /node_modules/casperjs/modules/events.js (and here I didn’t understand casperjs, although the node_modules folder). And there is just line 72:
EventEmitter.prototype.emit = function emit() {
  var type = arguments[0];
  // If there is no 'error' event listener then throw.
  if (type === 'error') {
    if (!this._events || !this._events.error ||
        (isArray(this._events.error) && !this._events.error.length))
    {
      if (arguments[1] instanceof Error) {
        throw arguments[1]; // Unhandled 'error' event
      } else {
        throw new CasperError("Uncaught, unspecified 'error' event.");
      }
    }
  }

  if (!this._events) return false;
  var handler = this._events[type];
  if (!handler) return false;

  if (typeof handler === 'function') {
    try {
      switch (arguments.length) {
        // fast cases
        case 1:
          handler.call(this);
          break;
        case 2:
          handler.call(this, arguments[1]);
          break;
        case 3:
          handler.call(this, arguments[1], arguments[2]);
          break;
        // slower
        default:
          var l = arguments.length;
          var args = new Array(l - 1);
          for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
          handler.apply(this, args);
      }
    } catch (err) {
      this.emit('event.error', err);
    }
    return true;

ADD
Error("Connection Timed Out"), socket, null, callback); this line was replaced with just console.log. 8-9 lines of such fall out, and then Error: socket hang up falls out. I did not find where to block this error. I don't have a tls.js file on my system. Kick-Ass. Infuriates.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Artur Atnagulov, 2016-01-07
@atnartur

So enter the captcha again. No one guarantees that the captcha will be requested only once. And it's probably still worth switching to the latest version of the API. Using an older version can also be suspicious. And suspicion causes captcha.

V
Vladislav Startsev, 2016-01-08
@esvlad

Well, the captcha is displayed due to frequent requests, as far as I know, therefore do not call more than 3 times per second, or use execute

D
Dmitry Belyaev, 2016-07-06
@alexdora

Unhandled 'error' event
uncaught error event
minify
socket.once('error', function (err) {
});
on the
socket.on('error', function (err) {
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question