Aerospike Python Client exception.ConnectionError: (-10, 'Socket read error: 11,

We are using aeropsike python client and are encountering many exception.ConnectionError: (-10, 'Socket read error: 11, xxx.xxx.xxx.xxx:3000, 47352', 'src/main/aerospike/as_socket.c', 248, False) happening.

It seems to be happening when we are running a query that applies a UDF.

def aggregate_rec(client, namespace, setname, as_ref_key):
    query = client.query(namespace, setname)
    query.select('field1', 'field2', 'field3')
    query.where(aerospike.predicates.equals('indexed-key', key))
    query.apply('udf_file', 'aggregate_records')
    subtotals = []

    def collect_subtotals(subtotal):
        subtotals.append(subtotal)

    def _aggregate_sumtotals(subtotals):
        totals = {'state1': 0, 'state2': 0, 'state3': 0, 'total': 0}
        if subtotals:
            for subtotal in subtotals:
                for k in subtotal.keys():
                    totals[k] += subtotal[k]
                    totals['total'] += subtotal[k]
        return totals

    query.foreach(collect_subtotals)
    return _aggregate_sumtotals(subtotals)

Any reason why would the client encounters ConnectionError when running such queries? How can I prevent this from happening?