<p>When I am attempting to index and create an array out of all the blockhashes on the blockchain I keep getting this error:</p>
<p>&quot;[WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted&quot;</p>
<pre><code>        block_counter = 0
        total_blocks = rpc_connection.getblockcount()
        while block_counter &lt; total_blocks:
            block_hash = rpc_connection.getblockhash(total_blocks)
            blockHashArray = np.append(blockHashArray, block_hash)
</code></pre>
<p>Am I getting this error due to an incoming transaction on my node? If so, how can I get around this issue?</p>

CC BY-SA 4.0
2024-01-29T05:51:42.297Z
In your code, the issue seems to stem from the fact that you're continuously trying to retrieve block hashes in a loop without properly managing the connection to your RPC server. Each call to `rpc_connection.getblockhash(total_blocks)` opens a new connection, and since you're not closing these connections, you eventually exhaust the available ports.

To resolve this issue, you should ensure that you properly close the connection after each call.
Mani T
CC BY-SA 4.0
2024-01-29T13:48:16.697Z
I figured it was something along those lines but I tried reading the documentation for bitcoinlib and don't find anything regarding how to close the RPC connection.

I tried deleting the rpc connection object, but that didn't work, and I tried using rpc_connection.stop() but that didn't seem to work either.
user2880722
CC BY-SA 4.0
2024-01-29T14:53:43.210Z
Just a quick follow up some other things I have tried with no success.

I tried to use the conn parameter in the AuthServiceProxy 

```def close(rpc_connection):
    rpc_connection._AuthServiceProxy__conn.close()
user2880722
<network><rpc-error-25>
multiple socket address usage error - using rpc to index block hashes
user2880722
# multiple socket address usage error - using rpc to index block hashes

(Asked by: username_0 on 2024-01-29)

When I am attempting to index and create an array out of all the blockhashes on the blockchain I keep getting this error:

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

```
        block_counter = 0
        total_blocks = rpc_connection.getblockcount()
        while block_counter < total_blocks:
            block_hash = rpc_connection.getblockhash(total_blocks)
            blockHashArray = np.append(blockHashArray, block_hash)

```

Am I getting this error due to an incoming transaction on my node? If so, how can I get around this issue?

**Tags:** network, rpc-error-25

> **Comments:**
> **username_1**: In your code, the issue seems to stem from the fact that you're continuously trying to retrieve block hashes in a loop without properly managing the connection to your RPC server. Each call to `rpc_connection.getblockhash(total_blocks)` opens a new connection, and since you're not closing these connections, you eventually exhaust the available ports.  To resolve this issue, you should ensure that you properly close the connection after each call.  
> **username_0**: I figured it was something along those lines but I tried reading the documentation for bitcoinlib and don't find anything regarding how to close the RPC connection.  I tried deleting the rpc connection object, but that didn't work, and I tried using rpc_connection.stop() but that didn't seem to work either.  
> **username_0**: Just a quick follow up some other things I have tried with no success.  I tried to use the conn parameter in the AuthServiceProxy   ```def close(rpc_connection):     rpc_connection._AuthServiceProxy__conn.close()  

---

## 0 answers

