Skip to content

Prevent API Calls During Startup and Index Creation#40

Merged
K0lin merged 10 commits intomainfrom
dev
Jan 5, 2026
Merged

Prevent API Calls During Startup and Index Creation#40
K0lin merged 10 commits intomainfrom
dev

Conversation

@K0lin
Copy link
Copy Markdown
Owner

@K0lin K0lin commented Jan 5, 2026

Overview

This PR implements comprehensive API blocking during application startup and database index creation to prevent database overload and data loss. The solution includes both backend middleware and frontend coordination to ensure the splash screen remains visible until all initialization processes are complete.

Resolves: Issue #36 - API calls during startup and index creation causing database overload and splash screen disappearing prematurely.

Changes

Backend API Blocking (HTTP 503)

  • Initial Load State Management: Added InitialLoadState struct with thread-safe tracking of initialization status
  • Middleware Implementation: Created initialLoadBlockingMiddleware that returns HTTP 503 for non-whitelisted endpoints during initialization
  • Whitelisted Endpoints: /api/v1/version, /api/v1/stats/log-processing, /api/v1/stats/summary remain accessible for frontend monitoring
  • Index Creation Tracking: Enhanced HTTPRequestRepository to track index creation status with IsIndexCreationActive() method

Processor Pause/Resume During Index Creation

  • SourceProcessor Enhancement: Added pause/resume functionality with Pause(), Resume(), and waitIfPaused() methods
  • Coordinator Integration: Implemented PauseAll() and ResumeAll() methods in the ingestion coordinator
  • Coordinated Pausing: Processors are automatically paused before index creation starts and resumed after completion
  • ProcessorPauser Interface: Added interface for coordinated pausing during database maintenance operations

Frontend Splash Screen Coordination

  • 503 Response Handling: Enhanced startup loader to properly handle HTTP 503 responses from blocked endpoints
  • Index Creation Waiting: Modified verifyDataAndFinish() to poll every 2 seconds after reaching 99% log processing until backend returns non-503 responses
  • Proper Completion: Fixed splash screen disappearance by using onReady() instead of location.reload() when initialization is complete

Technical Details

Backend Architecture

  • Thread-Safe State: Uses sync.RWMutex for concurrent access to initialization state
  • Background Index Creation: Indexes are created asynchronously with status tracking
  • Graceful Processor Control: Uses condition variables for efficient pause/resume operations

Frontend Behavior

  • Progressive Loading: Splash screen shows different messages for log processing vs index creation
  • Error Resilience: Handles API errors gracefully with retry logic and exponential backoff
  • Data Verification: Ensures data availability before allowing application access

Benefits

  1. Database Protection: Prevents overload during critical initialization phases
  2. Data Integrity: Pauses log processing during index creation to avoid data loss
  3. User Experience: Splash screen provides clear feedback throughout the entire initialization process
  4. System Reliability: Comprehensive blocking ensures consistent application state

@K0lin K0lin requested a review from quivalen January 5, 2026 00:07
@K0lin K0lin linked an issue Jan 5, 2026 that may be closed by this pull request
@K0lin K0lin self-assigned this Jan 5, 2026
Copy link
Copy Markdown
Collaborator

@quivalen quivalen left a comment

Choose a reason for hiding this comment

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

Overall looks good, with the exception of stats/summary

Why that is allowlisted ?

K0lin added 3 commits January 5, 2026 11:16
Removed ils.splashEnabled to prevent all endpoints (except those on the whitelist) from being blocked during the initial loading phase, even if the splash screen is disabled in the environment variables, in order to reduce the load on the data
Added non-root user for security in the Dockerfile.
@K0lin K0lin merged commit 4f6b9f6 into main Jan 5, 2026
3 checks passed
@K0lin K0lin deleted the dev branch January 5, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Processing logs is super slow when the UI is open

2 participants