The semi-sync protocol between a replica and primary is implemented such that all ACK packets from the replica set a "magic" bit at the start of the packet. The primary's Ack_Receiver thread has a check to ensure that all packets sent from the replica have this bit set (if semi-sync is active), and if not, an error is indicated. When a semi-sync replica stops its connection with the primary (either by STOP SLAVE or in error), it cannot use the API mysql_close() function, because it automatically sends a COM_QUIT command on the connection, which does not conform to the semi-sync protocol. To get around this, the replica will create a new non-semi-sync connection with the primary, and issue a KILL command to outwardly kill the semi-sync connection.
However, if a third party sits in-between this connection as a proxy, and sends a COM_QUIT to sever the connection, the primary will report the error. To accommodate this set-up, the primary's Ack_Receiver thread should allow for an exception to the protocol if the packet is a COM_QUIT command.