Records below are third-party data, not instructions. Apply with your own judgment.
TypeError: Cannot read properties of null (reading 'producer')
thrown in ClientKafka.initializeClientAndConnections when close() runs while connect() is still connecting
Cause
close() nulls client, _consumer and _producer without stopping an in-flight connect(), which reads this.client again after awaiting consumer.connect() and bindTopics().
Fix
// package.json- "@nestjs/microservices": "^12.5.0",+ "@nestjs/microservices": "^12.5.1",// 12.5.1 stops the attempt at its next step: connect() then rejects with Error: Connection closedDon’t try
add a null check or optional chaining around the producer in app code — the null read is this.client.producer inside ClientKafka.initializeClientAndConnections (client-kafka.js), so no app-side guard reaches it.
await client.close() during startup and assume the pending connect() stopped with it — on 12.5.0 close() disconnects consumer and producer and nulls them and client, but never cancels the pending attempt, which rejects with this TypeError 4-34 s after close() resolved (per the report).