Sunday, December 22, 2024

bitcoind – How does bitcoin core API work domestically (community) – bitcoinlib in python utilizing too many net sockets

I am making an attempt to grasp at a excessive degree, the native community features of calling the bitcoin core api by way of bitcoinlib in python

So the context round this query is that I wished to work on some python (for which I’ve very minimal expertise or understanding)
so I sat down to try to jot down a blockchain indexer. I run a full node and figured I’d see what I might do with the api.

Bitcoinlib gives a category referred to as AuthServiceProxy. You move the native api url & port to this, it appears like this:
rpc_connection = AuthServiceProxy(“http://person:[email protected]:8332″)

I dug a bit of bit into this class to seek out that it is utilizing httlib.HTTPConnection to open the connection itself.

        if connection:
            # Callables re-use the connection of the unique 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)

The very first thing I tried to do was to jot down a loop that might iterate over all of the blocks saved domestically to create an array out of the hashes of every block.

        whereas block_counter < total_blocks:
            rpc_connection = rpcConnector.rpcConnect()
            block_hash = rpc_connection.getblockhash(total_blocks)

that is basically how it’s getting referred to as. The rpcConnector is simply that AuthServiceProxy name basically.

So I ran this and printed the output of every block hash simply to see the way it was working. It labored up till concerning the 16200th iteration. Then it fails with the error message
“[WinError 10048] Just one utilization of every socket handle (protocol/community handle/port) is often permitted”. It fails at this mark every time I run it.

I assumed that perhaps the connections weren’t being closed out appropriately so I attempted a bunch of various issues to attempt to shut the connection inside every loop iteration
Nothing labored.

The very last thing I attempted was this: rpc_connection._AuthServiceProxy__conn.shut(). I figured because the AuthServiceProxy was simply utilizing HTTPConnection I might simply name the .shut()
I stepped via the code to see that it was in reality stepping into the .shut() methodology nevertheless it wasn’t ever hitting shut.

    def shut(self):
        """Shut the connection to the HTTP server."""
        self.__state = _CS_IDLE
        attempt:
            sock = self.sock
            if sock:
                self.sock = None
                sock.shut()   # shut it manually... there could also be different refs
        lastly:
            response = self.__response
            if response:
                self.__response = None
                response.shut()

each the Sock and Response have been None.

So perhaps this can be a networking query nevertheless it looks like once I name the API it isn’t preserving a connection open, so if that’s the case then my query is:
how am I utilizing up the addresses, and why is it all the time stopping round 16200?

and I suppose to shut it out, how can I resolve this concern?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles