From ecf8c574e4554ac9ccd3785d962af1d07d89b354 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 15 Sep 2024 13:03:11 +0800 Subject: [PATCH] :bug: Prevent wait group race --- pkg/internal/grpc/postman.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/internal/grpc/postman.go b/pkg/internal/grpc/postman.go index 043db0d..c206a74 100644 --- a/pkg/internal/grpc/postman.go +++ b/pkg/internal/grpc/postman.go @@ -2,9 +2,10 @@ package grpc import ( "context" + "sync" + "git.solsynth.dev/hydrogen/dealer/pkg/internal/services" "git.solsynth.dev/hydrogen/dealer/pkg/proto" - "sync" ) func (v *Server) DeliverNotification(ctx context.Context, request *proto.DeliverNotificationRequest) (*proto.DeliverResponse, error) { @@ -17,8 +18,8 @@ func (v *Server) DeliverNotificationBatch(ctx context.Context, request *proto.De for idx, provider := range request.GetProviders() { token := request.GetDeviceTokens()[idx] provider := provider + wg.Add(1) go func() { - wg.Add(1) services.DealDeliveryTask(&proto.DeliverNotificationRequest{ Provider: provider, DeviceToken: token, @@ -40,8 +41,8 @@ func (v *Server) DeliverEmailBatch(ctx context.Context, request *proto.DeliverEm var wg sync.WaitGroup for _, to := range request.GetTo() { to := to + wg.Add(1) go func() { - wg.Add(1) services.DealDeliveryTask(&proto.DeliverEmailRequest{ To: to, Email: request.GetEmail(),