Infinite loop of unable to connect

Im using Xbee as an I2C passthrough like this:
reboard(qwiic) → explorer → xbee : xbee ← explorer ← redboard (qwiic)

The xbee receives data just fine and half the time it works to send data from i2c to the other xbee. But the other half it gets caught in an infinite loop saying it cant connect. Here is the relevant code:


while True:
    time.sleep(0.2)  # Small delay to prevent overload
    try:
        # 1️⃣ Read from I2C (ESP32 sending data)
        ...

        # 2️⃣ Write back to I2C if we have received data from XBee
        ...

        # 3️⃣ Send data received from I2C over XBee
        if i2c_received_queue:
            try:
                data_to_send = i2c_received_queue.pop(0) #remove the first item.
                xbee.transmit(DEST_XBEE_ADDR, data_to_send)
                print("Sent Wirelessly (local_xbee --> remote xbee)", data_to_send)
            except Exception as e:
                print("Error sending from I2C overXbee:", e)
                i2c_received_queue.insert(0, data_to_send) #put it back at the front.
                print("Data re-queued.") # tell the user.
                time.sleep(1)

The output:

Data Length Read: 8
I2C Read (i2c --> local_xbee): b'testasdf'
Error sending from I2C overXbee: [Errno 7107] ENOTCONN
Data re-queued.
Error sending from I2C overXbee: [Errno 7107] ENOTCONN
Data re-queued.
Error sending from I2C overXbee: [Errno 7107] ENOTCONN

I would use serial but I dont have a way to solder it together right now.