From: Jérôme Benoit Date: Thu, 26 Mar 2026 16:42:21 +0000 (+0100) Subject: fix: respect elementAddDelay by using sequential startup when configured X-Git-Tag: ocpp-server@v3.4.0~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5f14c60844e65158b77170ae7f361ffbdf71c57e;p=e-mobility-charging-stations-simulator.git fix: respect elementAddDelay by using sequential startup when configured The perf commit 218fd550 switched to parallel Promise.allSettled for startup speed, but broke elementAddDelay since all stations launched simultaneously. Now uses sequential await loop when elementAddDelay > 0 and parallel allSettled when 0 or unset. Removes redundant outer try/catch — config errors propagate as fatal, station errors are handled per-station in both paths. --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index e232f291..80df1fa5 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -239,15 +239,30 @@ export class Bootstrap extends EventEmitter { // Start ChargingStation object instance in worker thread // eslint-disable-next-line @typescript-eslint/no-non-null-assertion for (const stationTemplateUrl of Configuration.getStationTemplateUrls()!) { - try { - const nbStations = stationTemplateUrl.numberOfStations - const addChargingStationTasks: Promise[] = [] + const nbStations = stationTemplateUrl.numberOfStations + const sequentialAdd = + (Configuration.getConfigurationSection( + ConfigurationSection.worker + ).elementAddDelay ?? 0) > 0 + if (sequentialAdd) { for (let index = 1; index <= nbStations; index++) { - addChargingStationTasks.push( - this.addChargingStation(index, stationTemplateUrl.file) - ) + try { + await this.addChargingStation(index, stationTemplateUrl.file) + } catch (error) { + console.error( + chalk.red( + `Error at starting charging station with template file ${stationTemplateUrl.file}: ` + ), + error + ) + } } - const results = await Promise.allSettled(addChargingStationTasks) + } else { + const results = await Promise.allSettled( + Array.from({ length: nbStations }, (_, i) => + this.addChargingStation(i + 1, stationTemplateUrl.file) + ) + ) for (const result of results) { if (result.status === 'rejected') { console.error( @@ -258,13 +273,6 @@ export class Bootstrap extends EventEmitter { ) } } - } catch (error) { - console.error( - chalk.red( - `Error at starting charging station with template file ${stationTemplateUrl.file}: ` - ), - error - ) } } const workerConfiguration = Configuration.getConfigurationSection(