diff --git a/client.h b/client.h index 4cc4061..bec5de8 100644 --- a/client.h +++ b/client.h @@ -134,6 +134,7 @@ public: int writeMqttPacketAndBlameThisClient(PublishCopyFactory ©Factory, char max_qos, uint16_t packet_id); int writeMqttPacketAndBlameThisClient(const MqttPacket &packet); bool writeBufIntoFd(); + bool isBeingDisconnected() const { return disconnectWhenBytesWritten; } bool readyForDisconnecting() const { return disconnectWhenBytesWritten && writebuf.usedBytes() == 0; } // Do this before calling an action that makes this client ready for writing, so that the EPOLLOUT will handle it. diff --git a/mqttpacket.cpp b/mqttpacket.cpp index 02aaf4a..f3ee26a 100644 --- a/mqttpacket.cpp +++ b/mqttpacket.cpp @@ -268,6 +268,11 @@ void MqttPacket::bufferToMqttPackets(CirBuf &buf, std::vector &packe void MqttPacket::handle() { + // It may be a stale client. This is especially important for when a session is picked up by another client. The old client + // may still have stale data in the buffer, causing action on the session otherwise. + if (sender->isBeingDisconnected()) + return; + if (packetType == PacketType::Reserved) throw ProtocolError("Packet type 0 specified, which is reserved and invalid.", ReasonCodes::MalformedPacket);