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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ynewmann
Copy link

@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.

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.

1 participant