SonarSource/sonarqube · warning
Error while executing monitoring task in
Error message
Error while executing monitoring task in {}: What it means
MainCollector schedules each monitoring task on a ScheduledExecutorService with scheduleWithFixedDelay. Any exception thrown by a task's run() is caught and logged with this warning so the scheduler is not cancelled by an unhandled exception.
Solutions
- Inspect the logged exception (the `e` argument) to find the root cause; this message itself is only a wrapper
- Check connectivity to the system the failed monitoring task polls (ES, DB)
- Restart/verify the web server process if the task keeps failing every period
- Fix the underlying task condition; the collector will keep retrying on its period
Defensive patterns
Strategy: try-catch
Validate before calling
// verify the system each monitoring task depends on is reachable before start assertEsReachable(); assertDbReachable();
Try / catch
try { task.run(); } catch (Exception e) { logger.warn("monitoring task {} failed", task.getClass().getSimpleName(), e); } Prevention
- Keep monitoring tasks defensive — never let exceptions escape run()
- Alert on recurrence of this warning rather than ignoring it
- Ensure dependencies (ES, DB) are up before starting the collector
When it happens
Trigger: Any monitoring task registered in MainCollector.start() throws an Exception during task.run(); the wrapper logs the task class simple name plus the exception.
Common situations: Elasticsearch temporarily unreachable; database hiccups during CE monitoring; transient network failures in webhooks/push-event polling tasks.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Can not register MBean [
- Elasticsearch indices are in read-only mode, likely due to…
- Elasticsearch nodes have critically low disk space
- Failed to poll for push events
- Failed to retrieve ES attributes. There will be only a…
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/5cf80b38c71eccb1.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-webserver-monitoring/src/main/java/org/sonar/server/monitoring/MainCollector.java:56
private ScheduledExecutorService scheduledExecutorService;
public MainCollector(MonitoringTask[] monitoringTasks) {
this.monitoringTasks = monitoringTasks;
}
@Override
public void start() {
this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat(getClass().getCanonicalName() + "-thread-%d")
.build());
Arrays.stream(monitoringTasks).forEach(task ->
scheduledExecutorService.scheduleWithFixedDelay(() -> {
try {
task.run();
} catch (Exception e) {
LOG.warn("Error while executing monitoring task in {}: ", task.getClass().getSimpleName(), e);
}
}, task.getDelay(), task.getPeriod(), MILLISECONDS));
}
@Override
public void stop() {
scheduledExecutorService.shutdown();
}
@VisibleForTesting
ScheduledExecutorService getScheduledExecutorService() {
return scheduledExecutorService;
}
}
View on GitHub (pinned to 184c821202)