Skip to content

Commit

Permalink
use time.NewTimer() to avoid possible memory leaks (prysmaticlabs#13800)
Browse files Browse the repository at this point in the history
Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
  • Loading branch information
2 people authored and ErnestK committed May 19, 2024
1 parent 8a45efb commit 5c2766d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion beacon-chain/rpc/prysm/v1alpha1/validator/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5c2766d

Please sign in to comment.