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

Raise OperationalError for socket timeouts #179

Merged
merged 5 commits into from
Aug 9, 2023

Conversation

jiezhen-chen
Copy link
Contributor

@jiezhen-chen jiezhen-chen commented Aug 1, 2023

Map socket timeout errors to OperationalError instead of InterfaceError

Description

socket.timeouts are a subclass within socket.error, and socket.error is classified as InterfaceError. Hence socket.timeouts gets classified as InterfaceError as well. This change will map socket.timeouts alone to OperationalError, where other exceptions within socket.errors will remain unchanged.

Motivation and Context

This PR resolves this issue

Testing

Conducted manual testing - hit timeout and received the below error message:

    raise OperationalError("connection time out", e)
redshift_connector.error.OperationalError: ('connection time out', TimeoutError(60, 'Operation timed out'))

Added unit test and integration test as well.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • Local run of ./build.sh succeeds
  • Code changes have been run against the repository's pre-commit hooks
  • Commit messages follow Conventional Commit Specification
  • I have read the README document
  • I have added tests to cover my changes
  • I have run all unit tests using pytest test/unit and they are passing.
  • By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jiezhen-chen jiezhen-chen reopened this Aug 4, 2023
@jiezhen-chen jiezhen-chen marked this pull request as ready for review August 4, 2023 19:28
Copy link
Contributor

@Brooke-white Brooke-white left a comment

Choose a reason for hiding this comment

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

there's a few performance test files that have changes, could we revert those?

@@ -658,7 +658,10 @@ def get_calling_module() -> str:
self._usock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
except socket.error as e:
self._usock.close()
raise InterfaceError("communication error", e)
if socket.timeout:
Copy link
Contributor

@Brooke-white Brooke-white Aug 4, 2023

Choose a reason for hiding this comment

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

this check needs to be reworked as socket.timeout will always be true. maybe something like this?

except socket.error.timeout as timeout_e:
  raise OperationalError("connection time out", timeout_e)
except socket.error as e:
  raise InterfaceError("communication error", e)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I don't believe that's true. In manual testing, this error only comes up when I either disconnect my network, or when I set timeout = 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right.... the evaluation of if socket.timeout will always return true. I'm now using two except blocks instead as you suggested. Thank you!

@jiezhen-chen jiezhen-chen force-pushed the OperationalError_for_timeouts branch from 546588c to d4e11c3 Compare August 6, 2023 21:11
@Brooke-white
Copy link
Contributor

@jiezhen-chen -- testing looks good, no regressions. if you could run the repo pre-commit hooks on this change I will go ahead and merge it

@Brooke-white Brooke-white self-requested a review August 9, 2023 20:05
@Brooke-white Brooke-white merged commit af2c9b1 into master Aug 9, 2023
@Brooke-white Brooke-white deleted the OperationalError_for_timeouts branch August 9, 2023 20:07
soksamnanglim pushed a commit to soksamnanglim/amazon-redshift-python-driver that referenced this pull request Aug 16, 2023
* Raise OperationalError for socket timeouts

* add unit test and integrationt test

* rectify unit test

* rectify integration test for socket_timeout

* remove empty config.ini
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