Skip to content

fix: Return the link to the connection pool after the node execution is completed#3919

Merged
shaohuzhang1 merged 1 commit intov1from
pr@v1@fix_connection
Aug 22, 2025
Merged

fix: Return the link to the connection pool after the node execution is completed#3919
shaohuzhang1 merged 1 commit intov1from
pr@v1@fix_connection

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Return the link to the connection pool after the node execution is completed

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Aug 22, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Aug 22, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

connection.close()

def run_node_async(self, node):
future = executor.submit(self.run_node, node)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no irregularities in the given code snippet. Here are some minor recommendations for improvement:

# Import necessary modules at the beginning to avoid circular imports or potential issues
from functools import reduce
from typing import List, Dict

import django
django.setup()  # Optional setup if not done elsewhere

from django.db import close_old_connections
from django.db.models import QuerySet
from django.utils import translation

The changes ensure that Django is properly initialized before being used, which might be important for certain operations depending on your use case.

Additionally, it's generally a good practice to check if connection has been defined before calling its methods. However, since you're closing it immediately after, this check won't apply but could serve as a reminder:

try:
    result = self.hand_event_node_result(
        current_node,
        node_result_future)
except Exception as e:
    print(f"An error occurred while processing {current_node}: {e}")
finally:
    try:
        close_old_connections()
        # If using async tasks, make sure to wait for all futures to complete
        node_result_future.result()
    except Exception as e:
        print("Exception during cleanup")
    finally:
        current_node.node_chunk.end()
        # Optionally, check if 'connection' exists before closing in production
        if hasattr(connection, 'close'):
            connection.close()

Make sure that when running these tasks asynchronously, you handle errors appropriately and possibly call .result() on the future to ensure all operations have completed before cleaning up resources.

@shaohuzhang1 shaohuzhang1 merged commit a0dc4c0 into v1 Aug 22, 2025
3 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v1@fix_connection branch August 22, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant