Skip to content

Commit

Permalink
fix(hydrate): gracefully handle Workbench unavailability during startup
Browse files Browse the repository at this point in the history
The TAXII server was failing to start when Workbench was temporarily
unavailable during initialization. Modified startup sequence to:
- Ensure indexes are created regardless of hydration status
- Continue service startup even if initial hydration fails
- Defer hydration to scheduled job if initial attempt fails
- Add more detailed error logging

This change allows the TAXII server to start successfully and retry
hydration later, rather than failing completely when Workbench is
temporarily down.
  • Loading branch information
seansica committed Nov 17, 2024
1 parent e9369d6 commit ff6d4ef
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/hydrate/hydrate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class HydrateService implements OnModuleInit {

async onModuleInit() {
try {
// Ensure indexes first
await this.ensureIndex(
this.stixObjectModel.collection,
{ '_meta.createdAt': 1 },
Expand All @@ -52,11 +53,24 @@ export class HydrateService implements OnModuleInit {
{ background: true, name: 'taxii_object_lookup' }
);

this.logger.debug('Successfully ensured all required indexes');

// Try hydration only after indexes are created
if (this.options.hydrateOnBoot) {
await this.hydrate();
try {
this.logger.debug('Hydration on boot enabled - starting initial hydration');
await this.hydrate();
} catch (hydrateError) {
// Log but don't throw hydration errors during startup
this.logger.error(
'Initial hydration failed - will retry during next scheduled run',
hydrateError.stack
);
}
}
} catch (error) {
this.logger.error('Failed to ensure indexes', error);
// Only throw if we couldn't create indexes
this.logger.error('Failed to ensure indexes - cannot continue', error.stack);
throw error;
}
}
Expand Down

0 comments on commit ff6d4ef

Please sign in to comment.