'Mutex timeout in javscript does'nt show on what line in code the error occurs

I use Node v16.14.2 and run this program in the command prompt.

I have a little problem with using Mutex in javascript. The Mutex itself do work but sometimes it takes to long to aquire the Mutex and I run into the error:

C:\myproject\node_modules\async-mutex\lib\errors.js:4
exports.E_TIMEOUT = new Error('timeout while waiting for mutex to become available');
                    ^

Error: timeout while waiting for mutex to become available
    at Object.<anonymous> (C:\myproject\node_modules\async-mutex\lib\errors.js:4:21)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\myproject\node_modules\async-mutex\lib\Semaphore.js:4:16)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)

I have 2 things I wonder about:

  1. The error message doesn't show on what line this error occurs in my code which is a problem because I have perheps 20 different mutexes and I don't know which one has the problem. How to know on what line in my code this error occurs? (All other types of errors that is not related to the mutex shows which line the error occurs to mention)

  2. Is there a problem to let the code aquire the mutex anyway even if it is not avaliable (which probably is not a good idéa but still?)

Test code to reproduce the error. I have nested the same mutex just to illustrate the error.

var Mutex = require('async-mutex').Mutex;
var withTimeout = require('async-mutex').withTimeout;

const mutexWithTimeout = withTimeout(new Mutex(), 5000); //5 second timeout
_testfunction();
async function _testfunction() { 


    console.log("starting...");

    await mutexWithTimeout.runExclusive(async () => {

        console.log("I am inside the mutex now...");
        await mutexWithTimeout.runExclusive(async () => {
            console.log("Timeout will happen here because I am nested just to reproduce the error");

        });
    });
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source