Skip to content

Commit cce6630

Browse files
committed
feat: try to recreate the SSE connection if the sse was defined
1 parent 4ea7593 commit cce6630

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

packages/proxy/resync.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,19 @@ func runProjectSecretsRefresh(cache *Cache, domainURL *url.URL, httpClient *http
361361
Msg("Project secrets refresh completed")
362362
}
363363

364-
func startProjectPollingLoop(ctx context.Context, cache *Cache, domainURL *url.URL, httpClient *http.Client, projectId, envSlug string, interval time.Duration) {
364+
func startProjectPollingLoop(ctx context.Context, cache *Cache, domainURL *url.URL, httpClient *http.Client, projectId, envSlug string, interval time.Duration, onPollComplete func()) {
365365
ticker := time.NewTicker(interval)
366366
defer ticker.Stop()
367367

368+
firstTick := true
368369
for {
369370
select {
370371
case <-ticker.C:
371372
runProjectSecretsRefresh(cache, domainURL, httpClient, projectId, envSlug)
373+
if !firstTick && onPollComplete != nil {
374+
onPollComplete()
375+
}
376+
firstTick = false
372377
case <-ctx.Done():
373378
return
374379
}

packages/proxy/sse.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,20 @@ func (m *SSEManager) transitionToPolling(projectId, environmentSlug string) {
375375
// Resync the project cache immediately — events might have been missed during the outage
376376
go runProjectSecretsRefresh(m.cache, m.domainURL, m.resyncHttpClient, projectId, environmentSlug)
377377

378-
go startProjectPollingLoop(pollCtx, m.cache, m.domainURL, m.resyncHttpClient, projectId, environmentSlug, pollingFallbackInterval)
378+
// On each polling tick (except the first), attempt SSE reconnection
379+
retrySSE := func() {
380+
m.mu.Lock()
381+
ps, ok := m.pollingProjects[projectId]
382+
if !ok || ps.retryingSSE {
383+
m.mu.Unlock()
384+
return
385+
}
386+
ps.retryingSSE = true
387+
m.mu.Unlock()
388+
go m.attemptSSEReconnection(projectId, environmentSlug)
389+
}
390+
391+
go startProjectPollingLoop(pollCtx, m.cache, m.domainURL, m.resyncHttpClient, projectId, environmentSlug, pollingFallbackInterval, retrySSE)
379392
}
380393

381394
func (m *SSEManager) cancelPollingIfActive(projectId string) {

0 commit comments

Comments
 (0)