Skip to content

Commit

Permalink
just don't close db connection like recommanded by apsw
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Feb 19, 2025
1 parent 93908d0 commit 4651b33
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 31 deletions.
8 changes: 3 additions & 5 deletions counterparty-core/counterpartycore/lib/api/apiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,9 @@ def run_apiserver(
logger.info("Starting API Server process...")

def handle_interrupt_signal(signum, frame):
logger.warning("Keyboard interrupt received. Shutting down...")
raise KeyboardInterrupt
pass

Check warning on line 496 in counterparty-core/counterpartycore/lib/api/apiserver.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/api/apiserver.py#L496

Added line #L496 was not covered by tests
# logger.warning("Keyboard interrupt received. Shutting down...")
# raise KeyboardInterrupt

wsgi_server = None
parent_checker = None
Expand Down Expand Up @@ -539,9 +540,6 @@ def handle_interrupt_signal(signum, frame):

wsgi_server.run(server_ready_value, shared_backend_height)

except KeyboardInterrupt:
pass

finally:
logger.info("Stopping API Server...")

Expand Down
26 changes: 4 additions & 22 deletions counterparty-core/counterpartycore/lib/cli/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,8 @@ def run(self):
self.follower_daemon.start()

Check warning on line 764 in counterparty-core/counterpartycore/lib/cli/server.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/cli/server.py#L763-L764

Added lines #L763 - L764 were not covered by tests

def stop(self):
logger.warning("Shutting down...")
self.db.interrupt()
logger.info("Shutting down...")

Check warning on line 767 in counterparty-core/counterpartycore/lib/cli/server.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/cli/server.py#L767

Added line #L767 was not covered by tests
# self.db.interrupt()
# Ensure all threads are stopped
if self.backend_height_thread:
self.backend_height_thread.stop()
Expand All @@ -775,6 +775,8 @@ def stop(self):
self.api_status_poller.stop()
if self.apiserver_v1:
self.apiserver_v1.stop()
if self.apiserver_v2:
self.apiserver_v2.stop()
if self.follower_daemon:
self.follower_daemon.stop()

Check warning on line 781 in counterparty-core/counterpartycore/lib/cli/server.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/cli/server.py#L770-L781

Added lines #L770 - L781 were not covered by tests

Expand All @@ -787,26 +789,6 @@ def stop(self):
while not self.apiserver_v2.has_stopped():

Check warning on line 789 in counterparty-core/counterpartycore/lib/cli/server.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/cli/server.py#L788-L789

Added lines #L788 - L789 were not covered by tests
time.sleep(0.1)

# then close the database with write access
if self.db:
database.close(self.db)

# Now it's safe to check for WAL files
for db_name, db_path in [
("Ledger DB", config.DATABASE),
("State DB", config.STATE_DATABASE),
]:
try:
database.check_wal_file(db_path)
except exceptions.WALFileFoundError:
db_file = config.DATABASE if db_name == "Ledger DB" else config.STATE_DATABASE
db = database.get_db_connection(db_file, read_only=False, check_wal=False)
db.close()
except exceptions.DatabaseError:
logger.warning(
f"{db_name} is in use by another process and was unable to be closed correctly."
)

log.shutdown()
logger.info("Shutdown complete.")

Expand Down
8 changes: 4 additions & 4 deletions counterparty-core/counterpartycore/lib/parser/follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,11 @@ def run(self):
)

def stop(self):
logger.debug("Stopping RawMempoolParser...")
self.db.interrupt()

Check warning on line 381 in counterparty-core/counterpartycore/lib/parser/follow.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/parser/follow.py#L380-L381

Added lines #L380 - L381 were not covered by tests
if self.is_alive():
logger.debug("Stopping RawMempoolParser...")
self.stop_event.set()
self.join()
# if self.is_alive():
self.stop_event.set()
self.join()

Check warning on line 384 in counterparty-core/counterpartycore/lib/parser/follow.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/parser/follow.py#L383-L384

Added lines #L383 - L384 were not covered by tests


class NotSupportedTransactionsCache(metaclass=helpers.SingletonMeta):
Expand Down

0 comments on commit 4651b33

Please sign in to comment.