Skip to content

fix: handle empty requests in milvus search to avoid connection attempts - #36388

Merged
liferoad merged 2 commits into
apache:masterfrom
liferoad:fix-Milvus
Oct 6, 2025
Merged

fix: handle empty requests in milvus search to avoid connection attempts#36388
liferoad merged 2 commits into
apache:masterfrom
liferoad:fix-Milvus

Conversation

@liferoad

@liferoad liferoad commented Oct 4, 2025

Copy link
Copy Markdown
Contributor

Prevent unnecessary connection attempts by returning early when receiving empty requests

apache_beam/ml/rag/enrichment/milvus_search_it_test.py:577: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/pipeline.py:670: in __exit__
    self.result = self.run()
                  ^^^^^^^^^^
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/testing/test_pipeline.py:118: in run
    result = super().run(
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/pipeline.py:620: in run
    self._options).run(False)
                   ^^^^^^^^^^
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/pipeline.py:644: in run
    return self.runner.run_pipeline(self, self._options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/direct/direct_runner.py:245: in run_pipeline
    return runner.run_pipeline(pipeline, options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py:196: in run_pipeline
    self._latest_run_result = self.run_via_runner_api(
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py:223: in run_via_runner_api
    return self.run_stages(stage_context, stages)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py:470: in run_stages
    bundle_results = self._execute_bundle(
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py:795: in _execute_bundle
    self._run_bundle(
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py:1034: in _run_bundle
    result, splits = bundle_manager.process_bundle(
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/portability/fn_api_runner/fn_runner.py:1360: in process_bundle
    result_future = self._worker_handler.control_conn.push(process_bundle_req)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/portability/fn_api_runner/worker_handlers.py:389: in push
    response = self.worker.do_instruction(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/worker/sdk_worker.py:662: in do_instruction
    return getattr(self, request_type)(
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/worker/sdk_worker.py:693: in process_bundle
    bundle_processor = self.bundle_processor_cache.get(
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/worker/sdk_worker.py:514: in get
    processor = bundle_processor.BundleProcessor(
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/runners/worker/bundle_processor.py:1135: in __init__
    op.setup(self.data_sampler)
apache_beam/runners/worker/operations.py:875: in apache_beam.runners.worker.operations.DoOperation.setup
    with self.scoped_start_state:
apache_beam/runners/worker/operations.py:925: in apache_beam.runners.worker.operations.DoOperation.setup
    self.dofn_runner.setup()
apache_beam/runners/common.py:1568: in apache_beam.runners.common.DoFnRunner.setup
    self._invoke_lifecycle_method(self.do_fn_invoker.invoke_setup)
apache_beam/runners/common.py:1564: in apache_beam.runners.common.DoFnRunner._invoke_lifecycle_method
    self._reraise_augmented(exn)
apache_beam/runners/common.py:1609: in apache_beam.runners.common.DoFnRunner._reraise_augmented
    raise new_exn
apache_beam/runners/common.py:1562: in apache_beam.runners.common.DoFnRunner._invoke_lifecycle_method
    lifecycle_method()
apache_beam/runners/common.py:602: in apache_beam.runners.common.DoFnInvoker.invoke_setup
    self.signature.setup_lifecycle_method.method_value()
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/apache_beam/io/requestresponse.py:340: in setup
    self._caller.__enter__()
apache_beam/ml/rag/enrichment/milvus_search.py:411: in __enter__
    self._client = MilvusClient(**connection_params)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/pymilvus/milvus_client/milvus_client.py:65: in __init__
    self._using = create_connection(
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/pymilvus/milvus_client/_utils.py:49: in create_connection
    raise ex from ex
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/pymilvus/milvus_client/_utils.py:44: in create_connection
    connections.connect(
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/pymilvus/orm/connections.py:472: in connect
    connect_milvus(**kwargs, user=user, password=password, token=token, db_name=db_name)
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/pymilvus/orm/connections.py:426: in connect_milvus
    raise e from e
target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/pymilvus/orm/connections.py:418: in connect_milvus
    gh._wait_for_channel_ready(timeout=timeout)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pymilvus.client.grpc_handler.GrpcHandler object at 0x7f48ab4447d0>
timeout = 10.0

    def _wait_for_channel_ready(self, timeout: Union[float] = 10):
        if self._channel is None:
            raise MilvusException(
                code=Status.CONNECT_FAILED,
                message="No channel in handler, please setup grpc channel first",
            )
    
        try:
            grpc.channel_ready_future(self._channel).result(timeout=timeout)
            self._setup_identifier_interceptor(self._user, timeout=timeout)
        except grpc.FutureTimeoutError as e:
            self.close()
>           raise MilvusException(
                code=Status.CONNECT_FAILED,
                message=f"Fail connecting to server on {self._address}, illegal connection params or server unavailable",
            ) from e
E           RuntimeError: pymilvus.exceptions.MilvusException: <MilvusException: (code=2, message=Fail connecting to server on localhost:46805, illegal connection params or server unavailable)> [while running 'Enrichment/Enrichment-RRIO/_Call/ParDo(_CallDoFn)']

target/.tox-py313-ml/py313-ml/lib/python3.13/site-packages/pymilvus/client/grpc_handler.py:162: RuntimeError

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

Prevent unnecessary connection attempts by returning early when receiving empty requests
@github-actions github-actions Bot added the python label Oct 4, 2025
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @liferoad, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the Milvus search component would attempt to connect to the Milvus server even when provided with an empty list of search requests, leading to unnecessary resource consumption and potential errors. The fix introduces a simple but effective early return for empty inputs, thereby optimizing the component's behavior and improving its robustness by avoiding futile connection attempts.

Highlights

  • Prevented Unnecessary Connections: The change introduces an early exit mechanism to prevent the Milvus search component from attempting to establish a connection when there are no actual search requests to process.
  • Optimized Empty Request Handling: An explicit check for empty input requests (reqs) has been added, ensuring that if the request list is empty, an empty result is returned immediately without further processing or connection attempts.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@liferoad
liferoad requested a review from damccorm October 4, 2025 02:15
@github-actions

github-actions Bot commented Oct 4, 2025

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@liferoad
liferoad requested review from damccorm and removed request for damccorm October 5, 2025 00:10
@liferoad
liferoad merged commit 517bef3 into apache:master Oct 6, 2025
114 of 120 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants