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

Ensure query is canceled after account rewind. #893

Merged
merged 8 commits into from
Feb 24, 2022

Conversation

winder
Copy link
Contributor

@winder winder commented Feb 23, 2022

Summary

Make sure the transaction query is canceled when exiting the AccountAtRound function.

Test Plan

Manual testing. Query psql for active queries. Verified a specific problematic query before and after this change.

@winder winder force-pushed the will/cancel-accountatround branch from 1209bbd to 757e7ad Compare February 23, 2022 16:41
@@ -99,7 +99,13 @@ func AccountAtRound(ctx context.Context, account models.Account, round uint64, d
MinRound: round + 1,
MaxRound: account.Round,
}
ctx, cf := context.WithCancel(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the code is fine, but please use a different variable name for ctx to avoid variable shadowing.
Also, I'd suggest you'll defer the cf before the db.Transactions call. ( i.e. so that if the db.Transactions call get panicked, the context would still get destroyed )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was intentional since I didn't want ctx to be used afterwards, and I didn't think it was worth breaking out a helper function. Does that make sense or would you still prefer to avoid shadowing?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's ok that you don't want to use it afterward.. the naming would just make sure the reader would understand it's a different object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using defer cf() is a little problematic because the logic would now depend on the evaluation order of defer. I think splitting the function in half should make the order clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, splitting up the function forces them to be backwards. It occurs to me now that I can simply call cf multiple times.

Copy link
Contributor

@tolikzinovyev tolikzinovyev left a comment

Choose a reason for hiding this comment

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

Looks good, but CI is failing.

Copy link
Contributor

@tolikzinovyev tolikzinovyev left a comment

Choose a reason for hiding this comment

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

I think we need to make sure to drain the channel in api/handler.go fetchAccounts() as well. There, if rewind fails, we just exit the range loop.

@winder winder requested a review from tolikzinovyev February 23, 2022 20:33
@tolikzinovyev
Copy link
Contributor

@winder have you figured out why CI is failing?

@winder
Copy link
Contributor Author

winder commented Feb 23, 2022

@winder have you figured out why CI is failing?

I think there are 2 issues.

  1. We have an e2e test that uses algod's e2e subs. It was changed recently to include the python scripts, which had been missing previously.
  2. There seems to be a new issue with the go-algorand build taking a long time. I haven't seen that before and am wondering if the circle CI resources are somehow overloaded and the build is taking a long time.

@tolikzinovyev
Copy link
Contributor

@winder have you figured out why CI is failing?

I think there are 2 issues.

1. We have an e2e test that uses algod's e2e subs. It was changed recently to include the python scripts, which had been missing previously.

2. There seems to be a new issue with the go-algorand build taking a long time. I haven't seen that before and am wondering if the circle CI resources are somehow overloaded and the build is taking a long time.

From the logs, make test is failing. So it's neither of those two issues.

var outCh <-chan idb.TxnRow
ch := make(chan idb.TxnRow)
var outCh <-chan idb.TxnRow = ch
close(ch)
Copy link
Contributor Author

@winder winder Feb 24, 2022

Choose a reason for hiding this comment

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

@tolikzinovyev this was the test bug. The channel must be closed now otherwise the channel can't be drained.


db := &mocks.IndexerDb{}
db.On("GetSpecialAccounts").Return(transactions.SpecialAddresses{}, nil)
db.On("GetSpecialAccounts", mock.Anything).Return(transactions.SpecialAddresses{}, nil)
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'm not sure why this one was working. It should have started failing once we added the context to this function.

- run: make test
- run:
command: make test
no_output_timeout: 15m
Copy link
Contributor Author

Choose a reason for hiding this comment

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

go test times out after 10 minutes. Change the CircleCI timeout to something larger than that so that the timeout error is properly reported.

@codecov-commenter
Copy link

codecov-commenter commented Feb 24, 2022

Codecov Report

Merging #893 (1a5ea7d) into develop (860ed09) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #893      +/-   ##
===========================================
+ Coverage    58.73%   58.77%   +0.04%     
===========================================
  Files           38       38              
  Lines         4495     4500       +5     
===========================================
+ Hits          2640     2645       +5     
  Misses        1528     1528              
  Partials       327      327              
Impacted Files Coverage Δ
accounting/rewind.go 35.95% <100.00%> (+3.01%) ⬆️
api/handlers.go 69.27% <100.00%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b0ebfd...1a5ea7d. Read the comment docs.

@winder winder merged commit e3ebf75 into develop Feb 24, 2022
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.

6 participants