Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling discard() after mutations throws the error: "Transaction has been aborted, please retry." (Code 10) #48

Closed
alexdslva opened this issue Jan 3, 2019 · 1 comment
Labels
area/usability Issues with usability and error messages kind/bug Something is broken. status/accepted We were able to reproduce the issue and accept to work on it.

Comments

@alexdslva
Copy link

Hello!

I think the client has a strange behavior when we call discard() after some mutations: it throws the following error : Transaction has been aborted. Please retry. I don't think it is useful, because if I call this method, it's precisely because I want to abort the transaction (and didn't call commit())...

In this case, I noticed that the error object has an additionnal property code with the value 10, and the following is false: e == dgraph.ERR_ABORTED.

Although the error message is the same, the error thrown when a conflict occurs during a transaction doesn't have this property code, and we can assert that: e == dgraph.ERR_ABORTED.

In my project, I currently monkey-patch the library the following way...

// Change behavior of discard.
// When calling discard() after mutations, it throws the error "10 ABORTED: Transaction has been aborted. Please retry.";
const _discard = Txn.prototype.discard;
Txn.prototype.discard = async function() {
    try {
        await _discard.apply(this, arguments);
    } catch (e) {
        if (e.code != 10) throw e;
    }
};

It is annoying because, usually, the call to discard() occurs in a finally block, so the error is not handled properly.

What do you think about this issue? Is this a desired behavior?
Thanks in advance for your answers. :)

@paulftw
Copy link

paulftw commented Mar 5, 2019

@alexandredasilva thank you for reporting this issue and taking your time to investigate it further.

It does look like a bug - i will try to reproduce it locally and if it's still happening will definitely fix it.

I suspect this is caused by another write transaction that has been committed before discard() and made the one being discarded a conflict. But server code to check for transaction conflicts is probably executed before the check of whether we want to commit or discard, resulting in an unnecessary error.

But that's a wild guess, will spend more time on it.

@prashant-shahi prashant-shahi added area/usability Issues with usability and error messages kind/bug Something is broken. status/accepted We were able to reproduce the issue and accept to work on it. labels Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/usability Issues with usability and error messages kind/bug Something is broken. status/accepted We were able to reproduce the issue and accept to work on it.
Development

No branches or pull requests

3 participants