Skip to content

feat: made changes to avoid spinning up multiple go-rouintes and bettor error handling#50

Merged
varonix0 merged 3 commits intomainfrom
feat/operator-fix
Feb 3, 2026
Merged

feat: made changes to avoid spinning up multiple go-rouintes and bettor error handling#50
varonix0 merged 3 commits intomainfrom
feat/operator-fix

Conversation

@akhilmhdh
Copy link
Copy Markdown
Member

This PR revamps the instant update setup we are doing. Instead of spinning up go-routines it handles it more gracefully.

  1. Check for parameter for connection changed or not. If not changed reuse existing connecting
  2. Better event registry setup for each connection
  3. Each registry is initialled for each CRD as of now
@akhilmhdh akhilmhdh requested a review from varonix0 February 3, 2026 07:43
@akhilmhdh
Copy link
Copy Markdown
Member Author

Tested various states

  1. Instant update Off
  2. Instant update ON but plan not allowed
  3. Instant update ON
  4. Instant update reconcile
  5. Secret reconcile with states
  6. Error handling of queue
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Feb 3, 2026

Greptile Overview

Greptile Summary

This PR refactors the instant updates (SSE) implementation to avoid spinning up multiple goroutines and improve connection management.

Key changes:

  • Replaced channel-based SSE architecture with callback-based pattern to reduce goroutine proliferation
  • Implemented connection reuse by checking if params changed before reconnecting
  • Added lazy SSE registry initialization (created only when InstantUpdates is enabled)
  • Added reconnection logic with exponential backoff (max 5 retries)
  • Made SSE errors non-fatal - reconciliation continues with periodic sync as fallback
  • Added explicit SSE cleanup in CRD update/delete handlers

Issues found:

  • Logic bug: Initial nil value for ServerSentEvents at line 609 breaks preservation logic at line 710
  • Race condition: SSE registry operations lack proper locking when updating resource variables map
  • Compatibility: Uses Go 1.22 syntax (range over integer, min builtin) - verify minimum Go version

Confidence Score: 2/5

  • This PR has critical logic bugs that will prevent the instant updates feature from working correctly
  • Score reflects critical initialization bug that breaks SSE registry preservation, potential race condition in concurrent map access, and Go version compatibility issues that may cause compilation failures
  • Pay close attention to internal/services/infisicalsecret/reconciler.go lines 609 and 898-926 for the initialization and race condition bugs

Important Files Changed

Filename Overview
internal/controller/infisicalsecret_controller.go Added explicit SSE cleanup before context cancellation in update/delete handlers and made SSE errors non-fatal for reconciliation
internal/services/infisicalsecret/reconciler.go Refactored SSE connection management with lazy initialization and connection reuse logic; contains potential race condition and initialization bug
internal/util/sse/sse.go Complete rewrite of SSE connection handling with callback-based architecture, reconnection with exponential backoff, and proper lifecycle management; uses Go 1.22 syntax
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Copy link
Copy Markdown
Member

@varonix0 varonix0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: have we done performance benchmarking on this? if so, how does it look like from your testing?

@varonix0 varonix0 merged commit 1a85a20 into main Feb 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants