Unexpected Data Overlap

First, I’ll describe the connector’s work, and then I’ll talk about the problem.

My connector converts incoming XML messages into JSON.

The JSON has a structure like this:

{
  "msg_type": "SRESPONSE",
  "sresponse": {
    # here some info about response
  },
  "process_id": "228762da-bf91-410e-935e-9d6bf0d7014d",
  "msg_id": "228762da-bf91-410e-935e-9d6bf0d7014d"
}

The sresponse contains useful information, including a list of codes (the list can be of any length, from one to tens of thousands).

When a client sends a document, the function is called:

def sftp_may_ctt_user_conn_event(client, datab, filename):
    logging.info("Got (%s) from user for (%s)-(%s)", datab, client.name, client.system)
    return CustomRequest(client, IncomingDocumentFactory, datab, filename).receipt()

CustomRequest.receipt() returns a Boolean value, which is beyond the scope of the question. The main thing here is that a new CustomRequest object is created.

IncomingDocumentFactory creates an object of the required class depending on the type of incoming message. In this particular case, an SResponse object is created:

class SResponse:
    def __init__(self, xml):
        self.xml_ = xml
        self.map_default_params(MAPPINGS["SGTIN_RESPONSE"]["DEFAULT"])
        self.map_buffer_params(MAPPINGS["SGTIN_RESPONSE"]["XML"])
        ...

The map_default_params and map_buffer_params methods create a dictionary and fill it with values from the incoming message.

The mapping looks like this:

    "SRESPONSE": {
        "DEFAULT": {
            "msg_type": "SRESPONSE",
            "sresponse": {},
        },
        "XML": {
            "DocumentHeader/DocumentIdentification/originalGUID": "process_id",
            "DocumentHeader/DocumentIdentification/GUID": "msg_id",
            "OperationsInstruction/OperationsTransaction/lotNumber": "sresponse/series",
            ...
        },

Processing of other message types is also handled in the same key.
We process several tens of thousands of messages from clients per day, and there are no problems.

Yesterday something strange happened.
A client sent almost simultaneously two messages of the same type (one with about 3000 codes, and the other with about 65000).

2024-05-13 06:39:58 1715582398.754 INFO callbacks - sftp_may_ctt_user_conn_event: Got ...
2024-05-13 06:39:59 1715582399.097 INFO callbacks - sftp_may_ctt_user_conn_event: Got ...

From the logs, I see that the original messages are different, but on the output, I got two JSONs with different process_id and msg_id (which corresponds to my expectations), but with the same sresponse part (with a list of codes of 3000 pieces)!

So, what I have: two CustomRequest objects were created, two SResponse objects were created, in which dictionaries were created, and part of one dictionary ended up in the other.

Python version 3.11.2