Node.js client library for auth0 timeout


I’m using Node.js client library for auto0( in my Machine to machine flow.

exports.onExecuteCredentialsExchange = async (event, api) => {
  const ManagementClient = require('auth0').ManagementClient;
  const management = new ManagementClient({
    domain: event.secrets.domain,
    clientId: event.request.body.client_id,
    clientSecret: event.request.body.client_secret,
    retry: { enabled: false }
  try {
    const res = await management.getClient({ client_id: event.request.body.client_id }) // freeze here
    if(res.client_metadata && res.client_metadata.org_id){
      let org_id = res.client_metadata.org_id;
      console.log('Fetching client metadata succeeded. m2m.org_id: ' + org_id + ' will be set in the access token');
      api.accessToken.setCustomClaim("m2m.org_id", org_id);
  } catch (e) {
    console.log('Fetching client metadata failed. reason: ' + e);

This code sometimes works fine in the test tab, but after I deploy it, it ends up timeout and get the error described below. After the error occurs, it fails even in the test tab.

  "code": 500,
  "details": "Error: Script execution time exceeded",
  "error": "Script generated an unhandled asynchronous exception.",
  "message": "Script execution time exceeded",
  "name": "Error"
  "total_request_duration_ms": 9819,
  "total_runtime_execution_duration_ms": 9816,
  "runtime_processing_duration_ms": 6,
  "action_duration_ms": 9767,
  "runtime_external_call_duration_ms": 43,
  "boot_duration_ms": 49,
  "network_duration_ms": 3

This question Random timeouts when using ManagementAPI seems to be th esimilar case, but I don’t think ISP is the problem in my case since I’m trying the code in the test tab.

I appreciate any suggestions or help. Thank you.