arangodb / arangojs

The official ArangoDB JavaScript driver.
https://arangodb.github.io/arangojs
Apache License 2.0
600 stars 106 forks source link

Timeout waiting to lock key Operation timed out: Timeout waiting to lock key #729

Closed vitalii-komenda closed 3 years ago

vitalii-komenda commented 3 years ago

I have the following code that throws sometimes Timeout waiting to lock key Operation timed out: Timeout waiting to lock key

    const tx = await db.beginTransaction({
        write: [
            'relations',
            'regionServices',
        ],
    });

    const key = 'some-key';

    await tx.step(() => db.query({
        query: `
            FOR node, rel IN 1..1 ANY @id relations
                REMOVE rel._key IN relations OPTIONS { ignoreErrors: true }
        `,
        bindVars: {
            id: `regionServices/${key}`,
        },
    }));
    await tx.step(() => db.query({
        query: `REMOVE @key IN @@collection OPTIONS { ignoreErrors: true }`,
        bindVars: {
            key: key,
            '@collection': 'regionServices',
        },
    }));
    const collection = await arangodb.getCollection('regionServices');
    await tx.step(() => collection.save({ name: key, _key: key }, { overwriteMode: 'update' }));

    await tx.commit();

Looks like after removing relations it locks the key and cannot insert same key anymore

vitalii-komenda commented 3 years ago

Does this run in transaction? await tx.step(() => collection.save({ name: key, _key: key }, { overwriteMode: 'update' }));