Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATAGO-93385/DATAGO-93864/Gracefully Terminate the Connector #85

Conversation

alimosaed
Copy link

What is the purpose of this change?

The connector does not terminate by a signal when the broker is attempting to connect. The root cause of the problem is that the connector attempts to establish a connection while creating a workflow. So, if it cannot connect, it cannot make the workflow. The current signal can terminate a component; however, no component is created in the above situation.

How is this accomplished?

Added some exception handling to the workflow creation logic and added a signal handling method to trigger an exception.

Anything reviews should focus on/be aware of?

The reviewer can focus on the exception handling solution and any possible edge cases.

Copy link

gitstream-cm bot commented Jan 29, 2025

Please mark whether you used Copilot to assist coding in this PR

  • Copilot Assisted

@alimosaed alimosaed changed the title DONOT REVIEW: Gracefully Terminate the Connector Gracefully Terminate the Connector Jan 29, 2025
Copy link
Author

Choose a reason for hiding this comment

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

Changes:

  • Added a try-exception around the connection logic.

  • Added the below logics to 1) wait till the connection is established 2) raise and exception and exit when a signal is triggered.

         # wait for the connection to complete
          while not self.stop_signal.is_set():
              done, _ = concurrent.futures.wait([result], timeout=0.1)
              if done:
                  break
    
          # disconnect and raise an exception if the stop signal is set
          if self.stop_signal.is_set():
              log.error(f"{self.error_prefix} Stopping connection attempt")
              self.disconnect()
              raise KeyboardInterrupt("Stopping connection attempt")
    

Copy link
Author

Choose a reason for hiding this comment

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

Changes:

  • Added a signal handler to trigger an exception. These exceptions can break the app.run() in any condition (either creating or running the workflow) and consequently calls the Shutdown() method (line #130) to stop and cleanup everything.

Copy link
Author

Choose a reason for hiding this comment

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

Changes:

  • Added exception handlers and removed duplicate stop and cleanup, as they are called by Shutdown method.

Copy link

@cyrus2281 cyrus2281 left a comment

Choose a reason for hiding this comment

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

Added a suggestion

The rest looks good

Copy link

@alimosaed alimosaed changed the title Gracefully Terminate the Connector DATAGO-93385/DATAGO-93864/Gracefully Terminate the Connector Feb 6, 2025
@alimosaed alimosaed merged commit 2c943be into main Feb 6, 2025
12 checks passed
@alimosaed alimosaed deleted the DATAGO-93385/AI-Connector-does-not-terminate-gracefully-when-the-broker-is-not-connected-initially branch February 6, 2025 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants