Skip to content

Commit

Permalink
fix(test)_: fix nested sql requests deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
friofry committed Jan 31, 2025
1 parent d1de5e7 commit 4ff5455
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions rpc/network/db/network_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (n *NetworksPersistence) GetNetworks(onlyEnabled bool, chainID *uint64) ([]
if err != nil {
return nil, err
}
defer rows.Close()

result := make([]*params.Network, 0, 10)
for rows.Next() {
Expand All @@ -94,22 +93,25 @@ func (n *NetworksPersistence) GetNetworks(onlyEnabled bool, chainID *uint64) ([]
if err != nil {
return nil, err
}
result = append(result, network)
}

if err = rows.Err(); err != nil {
return nil, err
}
rows.Close()

// Second loop to fetch providers and update networks in place
for i := range result {
// Fetch RPC providers for the network
providers, err := n.rpcPersistence.GetRpcProviders(network.ChainID)
providers, err := n.rpcPersistence.GetRpcProviders(result[i].ChainID)
if err != nil {
return nil, fmt.Errorf("failed to fetch RPC providers for chain_id %d: %w", network.ChainID, err)
return nil, fmt.Errorf("failed to fetch RPC providers for chain_id %d: %w", result[i].ChainID, err)
}
network.RpcProviders = providers
result[i].RpcProviders = providers

// Fill deprecated URLs if necessary (assuming this is a function you have)
FillDeprecatedURLs(network, providers)

result = append(result, network)
}

if err = rows.Err(); err != nil {
return nil, err
FillDeprecatedURLs(result[i], providers)
}

return result, nil
Expand Down

0 comments on commit 4ff5455

Please sign in to comment.