Skip to content

Comments

feat: Add max execution time per scan to prevent runaway scans #10#26

Open
bigjoe-io wants to merge 1 commit intoMDTechLabs:mainfrom
bigjoe-io:feature/add-scan-timeout-protection
Open

feat: Add max execution time per scan to prevent runaway scans #10#26
bigjoe-io wants to merge 1 commit intoMDTechLabs:mainfrom
bigjoe-io:feature/add-scan-timeout-protection

Conversation

@bigjoe-io
Copy link

@bigjoe-io bigjoe-io commented Jan 22, 2026

Closes #10

Impact

Prevents runaway scans from degrading system performance. Some contracts may hang analyzers, so this adds timeout protection.

Changes

  • ✅ Implement ScanService with Promise.race timeout mechanism
  • ✅ Add WorkerScanService for worker thread isolation (optional)
  • ✅ Create POST /scan endpoint with timeout protection
  • ✅ Add configurable timeout via SCAN_MAX_EXECUTION_TIME_MS env var
  • ✅ Implement graceful timeout error handling with clear messages
  • ✅ Add unit tests for timeout scenarios
  • ✅ Include comprehensive documentation

Implementation Details

  • Uses Node.js Promise.race() for lightweight timeout enforcement
  • Provides optional worker thread implementation for better isolation
  • Default timeout: 30 seconds (configurable)
  • Scans exceeding limit fail gracefully with clear error messages

Testing

  • Unit tests included in scan.service.spec.ts
  • Tests cover successful scans, timeout scenarios, and custom timeouts

Done Criteria

✅ Scans exceeding limit fail gracefully with clear error
✅ Uses Node.js process timeout (Promise.race)
✅ Provides worker constraints option
✅ Configurable via environment variables

- Implement ScanService with Promise.race timeout mechanism
- Add WorkerScanService for worker thread isolation
- Create POST /scan endpoint with timeout protection
- Add configurable timeout via SCAN_MAX_EXECUTION_TIME_MS env var
- Implement graceful timeout error handling with clear messages
- Add unit tests for timeout scenarios
- Include comprehensive documentation

Impact: Prevents runaway scans from degrading system performance
Done when: Scans exceeding limit fail gracefully with clear error
@mijinummi
Copy link
Collaborator

Hello @bigjoefilms , kindly resolve the conflict from your branch, you may need to pull from main

@mijinummi mijinummi self-requested a review January 22, 2026 21:54
Copy link
Collaborator

@mijinummi mijinummi left a comment

Choose a reason for hiding this comment

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

Please resolve the conflict

@mijinummi
Copy link
Collaborator

@bigjoefilms ???

@mijinummi
Copy link
Collaborator

please kindly try and resolve the conflict

@mijinummi mijinummi closed this Feb 1, 2026
@mijinummi mijinummi reopened this Feb 1, 2026
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.

2 participants