## [Unreleased]
+### Fixed
+
+- Ensure pool workers are properly initialized.
+
### Added
- HTTP server pool examples: express-cluster, express-hybrid.
}
private handleWorkerReadyResponse (message: MessageValue<Response>): void {
+ if (message.ready === false) {
+ throw new Error(`Worker ${message.workerId} failed to initialize`)
+ }
this.getWorkerInfo(
this.getWorkerNodeKeyByWorkerId(message.workerId)
).ready = message.ready as boolean
/** @inheritDoc */
protected handleReadyMessage (message: MessageValue<Data>): void {
- if (message.workerId === this.id && message.ready != null) {
- this.getMainWorker()?.on('message', this.messageListener.bind(this))
- this.sendTaskFunctionsListToMainWorker()
- this.sendToMainWorker({ ready: true, workerId: this.id })
+ if (message.workerId === this.id && message.ready === false) {
+ try {
+ this.getMainWorker()?.on('message', this.messageListener.bind(this))
+ this.sendTaskFunctionsListToMainWorker()
+ this.sendToMainWorker({ ready: true, workerId: this.id })
+ } catch {
+ this.sendToMainWorker({ ready: false, workerId: this.id })
+ }
}
}
protected handleReadyMessage (message: MessageValue<Data>): void {
if (
message.workerId === this.id &&
- message.ready != null &&
+ message.ready === false &&
message.port != null
) {
- this.port = message.port
- this.port.on('message', this.messageListener.bind(this))
- this.sendTaskFunctionsListToMainWorker()
- this.sendToMainWorker({ ready: true, workerId: this.id })
+ try {
+ this.port = message.port
+ this.port.on('message', this.messageListener.bind(this))
+ this.sendTaskFunctionsListToMainWorker()
+ this.sendToMainWorker({ ready: true, workerId: this.id })
+ } catch {
+ this.sendToMainWorker({ ready: false, workerId: this.id })
+ }
}
}