Tuesday, August 5, 2025
HomeBitcoinbitcoind - How does bitcoin core API work regionally (community) - bitcoinlib...

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


I am making an attempt to grasp at a excessive degree, the native community facets 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 aim to put in writing a blockchain indexer. I run a full node and figured I might see what I may do with the api.

Bitcoinlib gives a category known as AuthServiceProxy. You go the native api url & port to this, it appears like this:
rpc_connection = AuthServiceProxy(“http://consumer:[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 put in writing a loop that might iterate over all of the blocks saved regionally 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 primarily how it’s getting known as. The rpcConnector is simply that AuthServiceProxy name primarily.

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

I assumed that possibly the connections weren’t being closed out accurately 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 for the reason that AuthServiceProxy was simply utilizing HTTPConnection I may simply name the .shut()
I stepped by means of the code to see that it was in actual fact entering into the .shut() technique however it wasn’t ever hitting shut.

    def shut(self):
        """Shut the connection to the HTTP server."""
        self.__state = _CS_IDLE
        strive:
            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 possibly it is a networking query however it looks like after I name the API it is not maintaining 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 assume to shut it out, how can I resolve this problem?

RELATED ARTICLES

Most Popular

Recent Comments