Skip to content

Commit

Permalink
fix/solve memory leak issue (#138)
Browse files Browse the repository at this point in the history
* (fix) Change to ensure the chain cookie file is released after reading it. Close cometbft connection when the client instance is closed.

* (fix) Solved error when closing the cookie file

---------

Co-authored-by: Abel Armoa <[email protected]>
  • Loading branch information
aarmoa and Abel Armoa authored Jun 4, 2023
1 parent 0b80e40 commit d5dbabe
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ func NewChainClient(
}

// create file if not exist
os.OpenFile(defaultChainCookieName, os.O_RDONLY|os.O_CREATE, 0666)
cookie_file, err := os.OpenFile(defaultChainCookieName, os.O_RDONLY|os.O_CREATE, 0666)
if err != nil {
cc.logger.Errorln(err)
}
defer cookie_file.Close()

// attempt to load from disk
data, err := os.ReadFile(defaultChainCookieName)
Expand Down Expand Up @@ -480,6 +484,10 @@ func (c *chainClient) Close() {
if c.conn != nil {
c.conn.Close()
}

if c.cometbftClient != nil {
c.cometbftClient.Stop()
}
}

func (c *chainClient) GetBankBalances(ctx context.Context, address string) (*banktypes.QueryAllBalancesResponse, error) {
Expand Down

0 comments on commit d5dbabe

Please sign in to comment.