Transaction hangs if log level is debug

Hi,

We found that if the log level of the root logger is set to DEBUG, transactions hang indefinitely. I inserted a simple script to trigger the behavior. The document shouldn’t exist before running the script so the code will go to transaction branch.

import datetime
import logging.config
import sys

import couchbase
from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import Cluster
from couchbase.exceptions import (
    DocumentExistsException,
    DocumentNotFoundException,
)
from couchbase.options import ClusterOptions
from couchbase.transactions import AttemptContext

COUCHBASE_CLUSTER = 'couchbase://localhost'
COUCHBASE_BUCKET = 'control'
COUCHBASE_USERNAME = 'Administrator'
COUCHBASE_PASSWORD = 'password'


def run_dummy_transaction():
    # Initialize the Couchbase cluster
    cluster = Cluster(COUCHBASE_CLUSTER, ClusterOptions(
        PasswordAuthenticator(COUCHBASE_USERNAME, COUCHBASE_PASSWORD)
    ))
    bucket = cluster.bucket(COUCHBASE_BUCKET)
    collection = bucket.default_collection()

    doc_id = 'dummy-doc'
    doc_content = {'name': 'dummy', 'type': 'test'}

    try:
        collection.get_and_lock(doc_id, datetime.timedelta(seconds=15))
    except DocumentNotFoundException:
        def txn_logic(ctx: AttemptContext):
            try:
                ctx.insert(collection, doc_id, doc_content)
            except DocumentExistsException:
                pass

        cluster.transactions.run(txn_logic)
        logging.debug("Transaction committed successfully.")


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
    run_dummy_transaction()

Setting the log level to INFO solves the problem. Another solution is creating a different logger and configure the SDK to use that logger, as follows:

dummy_logger = logging.getLogger('cb')
dummy_logger.propagate = False
couchbase.configure_logging(dummy_logger.name, dummy_logger.level)

I wonder if we are doing something wrong, or if there is a side effect that we couldn’t identified.

Environment:

  • Couchbase Server Community 7.6.2
  • Couchbase SDK v4.3.0
  • Python 3.11.9

Thanks for reporting this. I opened a ticket.
https://couchbasecloud.atlassian.net/browse/PYCBC-1631

1 Like

Hi @turanPYCBC-1631 has been resolved and the fix will be available in the next release of the Python SDK (v4.3.4). The target release date is the 3rd Wednesday of the month. We do our best to stick to the target date, but sometimes the actual release date can slip a couple of days.

1 Like

Hi @turan – Following up to mention that v4.3.4 of the Python SDK has been released.

1 Like

Hi, just tested it, the new version fixed the problem. Thanks for working on it!

2 Likes