From 8580f34a02d6a85861effe90d2ef3599e6109e87 Mon Sep 17 00:00:00 2001 From: bnovil Date: Tue, 26 Mar 2024 15:52:52 +0800 Subject: [PATCH] use time.NewTimer() to avoid possible memory leaks --- beacon-chain/rpc/prysm/v1alpha1/validator/server.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/server.go b/beacon-chain/rpc/prysm/v1alpha1/validator/server.go index 1a33e36b0fe0..24751ebb9b26 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/server.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/server.go @@ -99,10 +99,15 @@ func (vs *Server) WaitForActivation(req *ethpb.ValidatorActivationRequest, strea return status.Errorf(codes.Internal, "Could not send response over stream: %v", err) } + waitTime := time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second + timer := time.NewTimer(waitTime) + defer timer.Stop() + for { + timer.Reset(waitTime) select { // Pinging every slot for activation. - case <-time.After(time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second): + case <-timer.C: activeValidatorExists, validatorStatuses, err := vs.activationStatus(stream.Context(), req.PublicKeys) if err != nil { return status.Errorf(codes.Internal, "Could not fetch validator status: %v", err)