Skip to content

Commit

Permalink
Fix timeout for webhook http request
Browse files Browse the repository at this point in the history
  • Loading branch information
AchoArnold committed Oct 9, 2023
1 parent c81ed85 commit f861ee1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions api/pkg/services/webhook_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,12 @@ func (service *WebhookService) sendNotification(ctx context.Context, event cloud
ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger)
defer span.End()

ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

request, err := service.createRequest(ctx, event, webhook)
if err != nil {
msg := fmt.Sprintf("cannot send [%s] event to webhook [%s] for user [%s]", event.Type(), webhook.URL, webhook.UserID)
msg := fmt.Sprintf("cannot create [%s] event to webhook [%s] for user [%s]", event.Type(), webhook.URL, webhook.UserID)
ctxLogger.Error(service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)))
return
}
Expand Down Expand Up @@ -230,9 +233,6 @@ func (service *WebhookService) createRequest(ctx context.Context, event cloudeve
ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger)
defer span.End()

ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

payload, err := json.Marshal(service.getPayload(ctxLogger, event, webhook))
if err != nil {
msg := fmt.Sprintf("cannot marshal payload for user [%s] and webhook [%s] for event [%s]", webhook.UserID, webhook.ID, event.ID())
Expand Down

0 comments on commit f861ee1

Please sign in to comment.