From aea9624175887cdb44a02011732832f8234842dd Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Wed, 7 Aug 2024 12:04:13 -0300 Subject: [PATCH] Fix concurrency issue when using `get_or_create` method --- CHANGELOG.md | 1 + docs/9.release-notes/_8.0_changelog.md | 1 + src/dipdup/config/__init__.py | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db72520ee..a248cb385 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic - cli: Fixed progress estimation when there are indexes with `last_level` option set. - cli: Don't save reports for successful test runs. +- database: Fixed concurrency issue when using `get_or_create` method. - evm: Fixed crash when contract ABI contains overloaded methods. - tezos.operations: Fixed `sr_cement` operation index subscription. diff --git a/docs/9.release-notes/_8.0_changelog.md b/docs/9.release-notes/_8.0_changelog.md index b9ce82eec..04a4b26ad 100644 --- a/docs/9.release-notes/_8.0_changelog.md +++ b/docs/9.release-notes/_8.0_changelog.md @@ -29,6 +29,7 @@ - config: Allow `sentry.dsn` to be empty string. - config: Fixed (de)serialization of hex strings in config. - config: Fixed setting logging levels according to the config. +- database: Fixed concurrency issue when using `get_or_create` method. - evm.events: Fixed matching logs when filtering by topic0. - evm.events: Improve fetching event batches from node. - evm.subsquid: Fixed typo in `iter_events` method name. diff --git a/src/dipdup/config/__init__.py b/src/dipdup/config/__init__.py index bb3b3a754..64bd63164 100644 --- a/src/dipdup/config/__init__.py +++ b/src/dipdup/config/__init__.py @@ -157,8 +157,10 @@ def __post_init__(self) -> None: @property def connection_string(self) -> str: + # NOTE: `maxsize=1` is important! Concurrency will be broken otherwise. + # NOTE: https://github.com/tortoise/tortoise-orm/issues/792 connection_string = ( - f'{self.kind}://{self.user}:{quote_plus(self.password)}@{self.host}:{self.port}/{self.database}' + f'{self.kind}://{self.user}:{quote_plus(self.password)}@{self.host}:{self.port}/{self.database}?maxsize=1' ) if self.schema_name != DEFAULT_POSTGRES_SCHEMA: connection_string += f'&schema={self.schema_name}'