{"record":{"id":"5cf80b38c71eccb1","repo":"SonarSource/sonarqube","slug":"error-while-executing-monitoring-task-in","errorCode":null,"errorMessage":"Error while executing monitoring task in {}: ","messagePattern":"Error while executing monitoring task in (.+?): ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/sonar-webserver-monitoring/src/main/java/org/sonar/server/monitoring/MainCollector.java","lineNumber":56,"sourceCode":"  private ScheduledExecutorService scheduledExecutorService;\n\n  public MainCollector(MonitoringTask[] monitoringTasks) {\n    this.monitoringTasks = monitoringTasks;\n  }\n\n  @Override\n  public void start() {\n    this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(\n      new ThreadFactoryBuilder()\n        .setDaemon(true)\n        .setNameFormat(getClass().getCanonicalName() + \"-thread-%d\")\n        .build());\n    Arrays.stream(monitoringTasks).forEach(task ->\n      scheduledExecutorService.scheduleWithFixedDelay(() -> {\n      try {\n        task.run();\n      } catch (Exception e) {\n        LOG.warn(\"Error while executing monitoring task in {}: \", task.getClass().getSimpleName(), e);\n      }\n    }, task.getDelay(), task.getPeriod(), MILLISECONDS));\n  }\n\n  @Override\n  public void stop() {\n    scheduledExecutorService.shutdown();\n  }\n\n  @VisibleForTesting\n  ScheduledExecutorService getScheduledExecutorService() {\n    return scheduledExecutorService;\n  }\n}\n","sourceCodeStart":38,"sourceCodeEnd":71,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-monitoring/src/main/java/org/sonar/server/monitoring/MainCollector.java#L38-L71","documentation":"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.","triggerScenarios":"Any monitoring task registered in MainCollector.start() throws an Exception during task.run(); the wrapper logs the task class simple name plus the exception.","commonSituations":"Elasticsearch temporarily unreachable; database hiccups during CE monitoring; transient network failures in webhooks/push-event polling tasks.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify the system each monitoring task depends on is reachable before start\nassertEsReachable(); assertDbReachable();","typeGuard":null,"tryCatchPattern":"try { task.run(); } catch (Exception e) { logger.warn(\"monitoring task {} failed\", task.getClass().getSimpleName(), e); }","preventionTips":["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"],"tags":["scheduler","monitoring","unexpected-exception"],"backgroundTag":"internal-invariant-violation","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}