fix: workers not exiting when using mutliple clusters (#435)

* fix: workers not exiting when using mutliple clusters

* refactor: use process.disconnect for cleaner exit
This commit is contained in:
AariaX
2026-01-03 17:48:29 +07:00
committed by GitHub
parent 0e8ca0c862
commit a8ddb65b21

View File

@@ -87,6 +87,7 @@ export class MicrosoftRewardsBot {
private pointsCanCollect = 0 private pointsCanCollect = 0
private activeWorkers: number private activeWorkers: number
private exitedWorkers: number[]
private browserFactory: Browser = new Browser(this) private browserFactory: Browser = new Browser(this)
private accounts: Account[] private accounts: Account[]
private workers: Workers private workers: Workers
@@ -115,6 +116,7 @@ export class MicrosoftRewardsBot {
} }
this.config = loadConfig() this.config = loadConfig()
this.activeWorkers = this.config.clusters this.activeWorkers = this.config.clusters
this.exitedWorkers = []
} }
get isMobile(): boolean { get isMobile(): boolean {
@@ -182,6 +184,11 @@ export class MicrosoftRewardsBot {
} }
const onWorkerDone = async (label: 'exit' | 'disconnect', worker: Worker, code?: number): Promise<void> => { const onWorkerDone = async (label: 'exit' | 'disconnect', worker: Worker, code?: number): Promise<void> => {
const { pid } = worker.process
if (!pid || this.exitedWorkers.includes(pid)) return
else this.exitedWorkers.push(pid)
this.activeWorkers -= 1 this.activeWorkers -= 1
this.logger.warn( this.logger.warn(
'main', 'main',
@@ -226,6 +233,7 @@ export class MicrosoftRewardsBot {
if (process.send) { if (process.send) {
process.send({ __stats: stats }) process.send({ __stats: stats })
} }
process.disconnect()
} catch (error) { } catch (error) {
this.logger.error( this.logger.error(
'main', 'main',