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

rpcclient: safe read and write to batch #2273

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

ynewmann
Copy link
Contributor

@ynewmann ynewmann commented Nov 8, 2024

This PR tries to make batchList concurrent-safe.

The Send() could panic at the line 1730 if c.removeRequest returned nil. It could return nil if we try to call Send() concurrently.

request := c.removeRequest(id)
// If there's an error, we log it and continue to the next
// request.
fullResult, err := json.Marshal(resp.Result)
if err != nil {
log.Errorf("Unable to marshal result: %v for req=%v",
err, request.id)
continue
}
// If there's a response error, we send it back the request.
var requestError error
if resp.Error != nil {
requestError = resp.Error
}
result := Response{
result: fullResult,
err: requestError,
}
request.responseChan <- &result

After the quick look I've noticed that there are places where the batchList is update unsafely. So, the simplest fix is just to add locks, but I'm afraid if it could break something else, because I'm not very familiar with the library.

@Roasbeef
Copy link
Member

Approved CI.

@coveralls
Copy link

coveralls commented Nov 22, 2024

Pull Request Test Coverage Report for Build 12370739640

Details

  • 0 of 24 (0.0%) changed or added relevant lines in 1 file are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.02%) to 57.259%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rpcclient/infrastructure.go 0 24 0.0%
Files with Coverage Reduction New Missed Lines %
rpcclient/infrastructure.go 2 39.87%
peer/peer.go 6 74.16%
Totals Coverage Status
Change from base Build 12253655920: -0.02%
Covered Lines: 29906
Relevant Lines: 52229

💛 - Coveralls

@guggero guggero self-requested a review November 22, 2024 07:37
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! Just two minor nits.

rpcclient/infrastructure.go Outdated Show resolved Hide resolved
rpcclient/infrastructure.go Show resolved Hide resolved
@ynewmann
Copy link
Contributor Author

Thanks for the fix! Just two minor nits.

One more nit here b3d9947

@ynewmann ynewmann requested a review from guggero November 25, 2024 13:51
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Can you squash the commits into one please?
Then this is good to go.

@ynewmann ynewmann force-pushed the fix/batch-data-race branch from a8cddef to d815651 Compare November 28, 2024 10:13
@ynewmann ynewmann requested a review from guggero December 16, 2024 10:54
@guggero guggero requested a review from yyforyongyu December 16, 2024 11:07
yyforyongyu added a commit to yyforyongyu/lnd that referenced this pull request Dec 17, 2024
@yyforyongyu
Copy link
Collaborator

Could you do a rebase on master? I'm trying to test it in lnd but the current branch doesn't include some recent fixes that were pushed to master.

@ynewmann ynewmann force-pushed the fix/batch-data-race branch from d815651 to db5318b Compare December 17, 2024 10:06
@ynewmann
Copy link
Contributor Author

Could you do a rebase on master? I'm trying to test it in lnd but the current branch doesn't include some recent fixes that were pushed to master.

done

yyforyongyu added a commit to yyforyongyu/lnd that referenced this pull request Dec 17, 2024
yyforyongyu added a commit to yyforyongyu/lnd that referenced this pull request Dec 18, 2024
yyforyongyu added a commit to yyforyongyu/lnd that referenced this pull request Dec 18, 2024
Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

@guggero guggero merged commit b1b1e95 into btcsuite:master Dec 18, 2024
3 checks passed
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.

5 participants