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

(web) enable inserting rows if you own the table #273

Closed
wants to merge 16 commits into from
Closed

Conversation

joewagner
Copy link
Contributor

@joewagner joewagner commented May 21, 2024

Copy link

vercel bot commented May 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2024 5:24pm

Copy link
Contributor Author

@joewagner joewagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asutula I've implemented the change requests. I also believe I found the nonce bug. That's included here too, but definitely let me know if you want me to move that to another PR.

@@ -1,6 +1,6 @@
{
"name": "@tableland/nonce",
"version": "1.0.0",
"version": "1.0.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asutula In the process of cleaning up this PR I was able to use the recent addition of the nonce debug logging to track down a race condition in how the delta value was being set. I'm 90% sure this is the issue that has been causing all of the test failures. The fix is currently included in this PR, but I can refactor into a separate PR if you'd like?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's fine. Leave it in here.

// Need to make sure we increment before returning the nonce value.
// Otherwise there is a race condition between other processes getting a
// nonce after the lock release and this call to increment.
await this.increment();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the issue. Since increment was being called after get nonce, the lock release was competing with the increment call and allowing alternate calls to getNonce to get the already used nonce.

if (transaction.nonce == null) {
transaction = { ...transaction };
transaction.nonce = await this.getNonce("pending");
await this.increment();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved inside of the getNonce method, see the comment above for more info.

@@ -43,11 +43,41 @@ const redis = new Redis({
token: process.env.KV_REST_API_TOKEN,
});

const GLOBAL_TEST_RUNNING = "GLOBAL_TEST_RUNNING";

const ensureSingularTest = async function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had originally thought that the issue was due to multiple test runners using the same store. This ensures that globally only one nonce test is run at a time. This didn't end up being the actual issue, but it seems like a good thing to have.

// We can't guarantee that sending 4 transactions from the same wallet will
// result in a nonce failure. This means that this test might fail
// occasionally, because of that it's being skipped here.
test.skip("sending transactions from two processes WITHOUT nonce manager fails", async function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the comment, I think we should skip this test since there's a potential for it to fail even though everything is working correctly. I believe that this test was actually failing because of the above issue with the increment race condition, so if tests start working consistently again we can unskip this in the future.

@asutula
Copy link
Contributor

asutula commented Jun 10, 2024

When I try to insert a row in a way that results in an error I see the normal error alert. Do you remember how you generated your error?

@joewagner the only error I see is the dev mode error toast provided by Nextjs (which is displayed for uhhandled errors). When I search the changes in this PR, I don't see any code related to triggering our own toast component. Maybe I'm missing somehting?

@joewagner
Copy link
Contributor Author

When I try to insert a row in a way that results in an error I see the normal error alert. Do you remember how you generated your error?

@joewagner the only error I see is the dev mode error toast provided by Nextjs (which is displayed for uhhandled errors). When I search the changes in this PR, I don't see any code related to triggering our own toast component. Maybe I'm missing somehting?

There isn't any new code in regard to error handling here. As you mention if there is an error, the error toast shows.
How are you generating an error?

@joewagner
Copy link
Contributor Author

joewagner commented Jun 10, 2024

@asutula In the case of some sort of invalid attempt to insert a row, the toast will pop up, then the sql logs show the details of the error in question.
As an example for discussion, if you create a table with a unique column constraint then try to insert the same value twice i see an error toast and a corresponding error in the sql logs.

I'm open to alternative ways of handling this kind of thing, or fixing if that's not what you are seeing?

@asutula
Copy link
Contributor

asutula commented Jun 13, 2024

Closing for now in favor of a more data driven approach that leverages react-hook-form's features.

@asutula asutula closed this Jun 13, 2024
@joewagner joewagner deleted the joe/data-edit branch July 30, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants