Auth0 Home Blog Docs

Request to Webtask got ESOCKETTIMEDOUT

webtask

#1

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,


#2

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?


#4

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.


#5

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.


#7

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


#8

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)


#9

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


#10

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


#12

Thanks I am Waiting for it


#13

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!”);
}
});

#14

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)


#15

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!