Closing out an httpconnection the correct way

33 views Asked by At

I am attempting to write a simple bitcoin blockchain indexer.

I've used the bitcoinlib library which contains an AuthServiceProxy module to connect via RPC.

Here's a snippet of the AuthServiceProxy class

            # Callables re-use the connection of the original proxy
            self.__conn = connection
        elif self.__url.scheme == 'https':
            self.__conn = httplib.HTTPSConnection(self.__url.hostname, port,
                                                  timeout=timeout)
        else:
            self.__conn = httplib.HTTPConnection(self.__url.hostname, port,
                                                 timeout=timeout)

I am creating connections in a loop to retrieve the hash of each block, but due to some socket limits am getting this error after about ~16000 iterations

[WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

My attempt to solve this error was to do this:

        while block_counter < total_blocks:
            block_hash = rpc_connection.getblockhash(total_blocks)
            blockHashArray = np.append(blockHashArray, block_hash)
            rpcConnector.close(rpc_connection)

def close(rpc_connection):
    rpc_connection._AuthServiceProxy__conn.close()

It didn't seem to have any affect, so I am wondering what I am missing.

0

There are 0 answers