Request to Webtask got ESOCKETTIMEDOUT

What I am trying to do is authenticate users using my own database. There I am following the guidelines mentioned in Articles at Auth0 web site here. I followed all the steps mentioned there for msql connection (including configuring my firewall to allow access to the specified addresses). Actually first I created the ‘Login’ database action script. But when I am going to ‘try’ it, the following error appears.

Request to Webtask got ESOCKETTIMEDOUT

How to get rid of this?

I referred this as well. No help,

Hey there ejcjayathma! “Request to Webtask got ESOCKETTIMEDOUT” is commonly thrown when there is an issue in requests made from a custom database connection script, hook, or rule. Is there by chance any further log information or details you could share with us that may help in troubleshooting what you’re experiencing?

This the script (given in custom scripts) I am trying to run,

function login(email, password, callback) {
  var connection = mysql({
    host: 'ip',
    user: 'user',
    password: 'password',
    database: 'project'
  });

  connection.connect();

  var query = "SELECT id, name, email, password " +
    "FROM users WHERE email = ?";

  connection.query(query, [email], function (err, results) {
    if (err) return callback(err);
    if (results.length === 0) return callback(new WrongUsernameOrPasswordError(email));
    var user = results[0];

bcrypt.compare(password, user.password, function (err, isValid) {
  if (err) {
    callback(err);
  } else if (!isValid) {
    callback(new WrongUsernameOrPasswordError(email));
  } else {
    callback(null, {
      id: user.id.toString(),
      name: user.name,
      email: user.email
    });
  }
});

});
}

here for the ‘ip’ I put my machine’s ip address and gave the relevant credentials as well.

I am waiting for a response.

On first glance your script looks fine, can we try adding some console.log()s to see if we can find more details on where the point of failure might be? You can also take a look at Real-time Webtask Logs extension to help gather more feedback as the webtask runs.

1 Like

I added the following after the line establishing connection.

connection.connect();
connection.connect(function(err) {
if (err) {
console.error(‘connecting Error’);
} else {
console.log(“Connected!”);
}
});

I am getting connecting Error

It looks like you’re getting connecting Error because that’s what you’re telling it to output as the error. I suggest having it dump the error it finds (via the err value you’re passing)

Now this is my code.

    function login(email, password, callback) {
      console.log(email);
      console.log(password);
      
     var connection = mysql({
       host: 'xxx',
       user: 'xxx',
       password: 'xxx',
        database: 'xxx'
     });
      console.log('here1');
      
connection.connect();
      connection.connect(function(err) {
        if (err) {
          console.log('connection error');
          console.log(err);
          return;
        } else {
          console.log('connected');
        }
    });
      
      console.log('here2');  
      
      var query = "SELECT id, name, email, password FROM 'project-travel'.users WHERE email = ?";
      
      connection.query(query, email, function (err, results) {
        console.log('here3');
        connection.end();
        if (err) return callback(err);
        if (results.length === 0) return callback(new WrongUsernameOrPasswordError(email));
        var user = results[0];

    bcrypt.compare(password, user.password, function (err, isValid) {
      if (err) {
        callback(err);
      } else if (!isValid) {
        callback(new WrongUsernameOrPasswordError(email));
      } else {
        callback(null, {
          id: user.id.toString(),
          name: user.name,
          email: user.email
        });
      }
    });

The console log is

11:00:26 PM:

 new webtask request 1535736626820.5519

11:00:26 PM:

 abc@google.com abc

11:00:26 PM:

 here1

11:00:26 PM:

 connection error

11:00:26 PM:

 { [Error: Cannot enqueue Handshake after already enqueuing a Handshake.] code: 'PROTOCOL_ENQUEUE_HANDSHAKE_TWICE', fatal: false } here2

11:01:26 PM:

 finished webtask request 1535736626820.5519 with HTTP 500 in 60167ms

Further when I remove connection.connect(); Log is as follows

11:05:22 PM:

new webtask request 1535736922646.492112

11:05:22 PM:

 abc@google.com abc

11:05:22 PM:

 here1

11:05:22 PM:

 here2

11:06:22 PM:

 finished webtask request 1535736922646.492112 with HTTP 500 in 60150ms

Please help me solve this

Ok so this is the actual error message you’re receiving… Let’s see what we can find out

1 Like

Thanks I am Waiting for it

The nested connection.connect() may have caused the [Error] Cannot enqueue Handshake after already enqueuing a Handshake. error. When you get a moment @ejcjayathma can you remove that and see what output we get from there?

So moving forward we would remove this section for the test:

connection.connect(function(err) {
if (err) {
console.error(‘connecting Error’);
} else {
console.log(“Connected!”);
}
});

When that is removed my code is

 function login(email, password, callback) {
          console.log(email);
          console.log(password);
      
     var connection = mysql({
       host: 'xxx',
       user: 'xxx',
       password: 'xxx',
        database: 'xxx'
     });
      console.log('here1');
      
      connection.connect();
              
      console.log('here2');  
      
      var query = "SELECT id, name, email, password FROM users WHERE email = ?";
      
      connection.query(query, email, function (err, results) {
        console.log('here3');
        
        if (err) return callback(err);
        if (results.length === 0) return callback(new WrongUsernameOrPasswordError(email));
        var user = results[0];
        connection.end();
    bcrypt.compare(password, user.password, function (err, isValid) {
      if (err) {
        callback(err);
      } else if (!isValid) {
        callback(new WrongUsernameOrPasswordError(email));
      } else {
        callback(null, {
          id: user.id.toString(),
          name: user.name,
          email: user.email
        });
      }
    });

the webtask log is
6:26:13 AM:

 new webtask request 1535763373774.673300

6:26:13 AM:

 jejc86@yahoo.com project

6:26:13 AM:

 here1

6:26:13 AM:

 here2

6:27:13 AM:

 finished webtask request 1535763373774.673300 with HTTP 500 in 60137ms

In the web browser log is
POST https://manage.auth0.com/api/try-login 401 (Unauthorized)

While investigating this issue I need to dig a little deeper, when you get a moment can you DM me your tenant name? Is it possible that you have a rule active that is interfering with your webtask? Thanks!

Hello, I have the exact same problem with the exact same error message in the logs. Any insight on how you were able to fix it?

Thanks.

Hi! Unfortunately I was not able to fix it. Since I was running out of time I used their database which made my work more complicated

having the same problem, did you guys were able to find the cause?

Hey @jerac.dialino @ejcjayathma, and @sonali4294, I am happy to take a look at this issue with you but I do need more information on the challenge you are facing. When you get a chance can you please direct message me your tenant names? Also Is it possible that you have an active rule that could be interfering with your webtask? Any additional information is appreciated so we can help you get this worked out. Thanks!

@jerac.dialino after looking at the script you sent and investigating your tenant I did not see an active custom db implementation. This presents a challenge when reproducing the issue. Often times when this error is presented with a custom database active it can mean the customer database took too long to respond a threw the ESOCKETTIMEOUT error. That being said I would be happy to investigate this further if we had more details available. Thanks in advance!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.