fix(growth): bound SSE authorization reads

This commit is contained in:
2026-08-21 01:50:11 +03:30
parent a15c04cac1
commit d3189ac8f4
2 changed files with 37 additions and 14 deletions

View File

@@ -142,7 +142,17 @@ func (s *Server) growthReportEvents(w http.ResponseWriter, r *http.Request) {
s.problem(w, r, http.StatusTooManyRequests, "RATE_LIMITED", "Too many growth report streams")
return
}
record, err := s.growth.Get(r.Context(), merchantID, id)
maxDuration := s.growthSSEMaxDuration
if maxDuration <= 0 {
maxDuration = defaultGrowthSSEMaxDuration
}
pollInterval := s.growthSSEPollInterval
if pollInterval <= 0 {
pollInterval = defaultGrowthSSEPollInterval
}
streamContext, cancel := context.WithTimeout(r.Context(), maxDuration)
defer cancel()
record, err := s.growth.Get(streamContext, merchantID, id)
if errors.Is(err, growthreport.ErrNotFound) {
s.problem(w, r, 404, "RESOURCE_NOT_FOUND", "Resource not found")
return
@@ -159,16 +169,6 @@ func (s *Server) growthReportEvents(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/event-stream; charset=utf-8")
w.Header().Set("Cache-Control", "no-cache, no-transform")
w.Header().Set("X-Accel-Buffering", "no")
maxDuration := s.growthSSEMaxDuration
if maxDuration <= 0 {
maxDuration = defaultGrowthSSEMaxDuration
}
pollInterval := s.growthSSEPollInterval
if pollInterval <= 0 {
pollInterval = defaultGrowthSSEPollInterval
}
streamContext, cancel := context.WithTimeout(r.Context(), maxDuration)
defer cancel()
ticker := time.NewTicker(pollInterval)
defer ticker.Stop()
heartbeat := time.NewTicker(15 * time.Second)