Closed fridary closed 3 months ago
Hello,
this depends on too many things, especially what the queries do on the server. If you are using different connections per thread there is just no shared structure (lock, variables) across connections, so I doubt that the lock happens in the client.
You need a professional consultancy to look into it, it's not a bug in the driver.
@dvarrazzo but there are absolutely no errors and it freezes. How can I catch an error? Maybe there is timeout
option in fetchone()
?
I changed connection to be declared once outside the Thread and it did not help. I also added this check if connection is not closed and reopen:
# declaring conn outside Thread()
conn = psycopg2.connect(**utils.db_config_psql, **utils.keepalive_kwargs)
def on_message(block_number):
try:
with conn.cursor() as cursor:
pass
except psycopg2.InterfaceError as e: # connection already closed
conn = psycopg2.connect(**utils.db_config_psql, **utils.keepalive_kwargs)
with conn.cursor() as cursor:
journal.write(f" Starting SELECT 1 FROM _blocks")
# ...
I have an linux service that runs
Thread()
every 12 second and do queries to database. Suddenly I notice that after 1-5 days my python script freezes and nothing happens. So I put a lot of breakpoints and found out that script hangs on these lines and nothing happens, no errors:Service is located in
/etc/systemd/system/
:eth_newHeads.py:
When hangs, I see this
journalctl --unit=eth_newHeads -n 100 --no-pager
:As we see, it hangs. Nowhere any errors. Last logs
service_output.log
andservice_error.log
I can see before script is hanged.Now, if I do
sudo systemctl restart postgresql@12-main
, it will begin to work andSuccess SELECT 1 FROM _blocks
is reached.I could think obvious the problem is in psql, but terminal commands work:
I need to say that there are psql v12 and v16 installed on Ubuntu both, but I use only v12. And
wallet_hunter
on v12.And the last at the moment of hang
sudo systemctl status postgresql@12-main
: