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

keystore watcher not release #45

Open
xinshengfan opened this issue Dec 13, 2022 · 1 comment
Open

keystore watcher not release #45

xinshengfan opened this issue Dec 13, 2022 · 1 comment

Comments

@xinshengfan
Copy link

xinshengfan commented Dec 13, 2022

I init in a injector method ensure grpc client init one time,such as:
`func InitTronGRpc() (*client.GrpcClient, func(), error) {
cfg := config.C.TronGrid
opts := make([]grpc.DialOption, 0)
opts = append(opts, grpc.WithInsecure())

conn := client.NewGrpcClient(cfg.RPCHost)

if err := conn.Start(opts...); err != nil {
	_ = fmt.Errorf("Error connecting GRPC Client: %v \n", err)
}
cleanFunc := func() {
	conn.Stop()
}
err := conn.SetAPIKey(cfg.ApiGrpcKey)
if err != nil {
	logger.Errorf(context.Background(), "init GRPC Client error %v ", err)
	_ = fmt.Errorf("ini GRPC Client err: %v \n", err)
	return nil, cleanFunc, err
}
_, err = account.ImportFromPrivateKey(
	cfg.OperatorPrivateKey,
	cfg.OperatorName,
	cfg.OperatorPassword)
if err != nil {
	logger.Errorf(context.Background(), "import private key error %v ", err)
	_ = fmt.Errorf("import private key err: %v \n", err)
}
return conn, cleanFunc, nil

}
`

and I call UnlockedKeystore in a service ,
I found UnlockedKeystore not release watcher goroutine, cause memory is full

func (tron *TronOperator) SignatureExecuteTx(ctx context.Context, tx *api.TransactionExtention, err error) (string, error) { ks, acct, _ := store.UnlockedKeystore(config.C.TronGrid.OperatorAddress, config.C.TronGrid.OperatorPassword) ctrlr := transaction.NewController(tron.TronGrpc, ks, acct, tx.Transaction) if err = ctrlr.ExecuteTransaction(); err != nil { return "", err } txId := utils.BytesToNo0xHexString(tx.GetTxid()) return txId, err }

all goroutine keep in memory, like this

1670922794829

How to solve ?
Thanks!

@gpassing
Copy link

did u solve problem

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

No branches or pull requests

2 participants