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

client/core: fix conns data races #1280

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/core/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func (c *Core) AccountDisable(pw []byte, addr string) error {
dc.cfgMtx.RUnlock()
// Disconnect and delete connection from map.
dc.connMaster.Disconnect()
c.connMtx.Lock()
delete(c.conns, dc.acct.host)
c.connMtx.Unlock()

return nil
}
Expand Down
5 changes: 3 additions & 2 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,9 @@ func (c *Core) dexConnections() []*dexConnection {
// exchangeMap creates a map of *Exchange keyed by host, including markets and
// orders.
func (c *Core) exchangeMap() map[string]*Exchange {
infos := make(map[string]*Exchange, len(c.conns))
Copy link
Member Author

Choose a reason for hiding this comment

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

It was the len(c.conns). I was just gonna remove the pre-alloc, but it's just as easy to grab the slice first and use it in the range

for _, dc := range c.dexConnections() {
dcs := c.dexConnections()
infos := make(map[string]*Exchange, len(dcs))
for _, dc := range dcs {
infos[dc.acct.host] = dc.exchangeInfo()
}
return infos
Expand Down