Handle "log gone" (PYTHON-1266) at the end of _run_loop by tlasica · Pull Request #1133 · apache/cassandra-python-driver · GitHub
Skip to content

Handle "log gone" (PYTHON-1266) at the end of _run_loop#1133

Merged
absurdfarce merged 1 commit into
apache:masterfrom
tlasica:patch-1
Jan 24, 2023
Merged

Handle "log gone" (PYTHON-1266) at the end of _run_loop#1133
absurdfarce merged 1 commit into
apache:masterfrom
tlasica:patch-1

Conversation

@tlasica

@tlasica tlasica commented Dec 28, 2022

Copy link
Copy Markdown
Contributor

If log is somehow gone and file exception due to the race mention in PYTHON-1266 it will also inevitably fail for the same reason after the loop so we need to catch the exception there as well.

I have hit it in some Cassandra dtest:

Exception in thread asyncore_cassandra_driver_event_loop (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
  File "/usr/lib/python2.7/threading.py", line 754, in run
  File "/dse/dse-db/bin/../lib/cassandra-driver-internal-only-3.25.0.zip/cassandra-driver-3.25.0/cassandra/io/asyncorereactor.py", line 262, in _run_loop
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'debug'

If log is somehow gone and file exception due to the race mention in PYTHON-1266
it will also inevitably fail for the same reason after the loop
so we need to catch the exception there as well.
@tlasica tlasica marked this pull request as ready for review December 28, 2022 07:06
@tlasica tlasica changed the title Handle "log gone" case in the end of _run_loop Handle "log gone" (PYHON-1266) in the end of _run_loop Dec 28, 2022
@tlasica tlasica changed the title Handle "log gone" (PYHON-1266) in the end of _run_loop Handle "log gone" (PYHON-1266) at the end of _run_loop Dec 28, 2022
@tlasica tlasica changed the title Handle "log gone" (PYHON-1266) at the end of _run_loop Handle "log gone" (PYTHON-1266) at the end of _run_loop Dec 28, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given that this verbiage is already used for the existing logging try/catch in this method we're starting to get into some ugly duplication here. Prolly worth pulling this out into a function, something like:

def maybe_log_debug(*args, **kwargs)
    try:
        log.debug(*args, **kwargs)
    except Exception:
        # TODO: Remove when Python 2 support is removed
        # PYTHON-1266. If our logger has disappeared, there's nothing we
        # can do, so just log nothing.
        pass

and then call with appropriate params.

This is a relatively minor thing so I can prolly also just clean it up after this gets merged if you don't wanna muck with it @tlasica. Either way is good with me!

@tlasica tlasica Jan 5, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about it, but I decided not to do it:

  1. there are 2 occurences, my rule of thumb is 3
  2. all are local in the same function

TLDR I think it is not worth it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No worries, I can take care of it. Thanks for the fix @tlasica!

@pepgid

pepgid commented Jan 6, 2023

Copy link
Copy Markdown

Perhaps it is prudent to gateway language version sensitive areas of the code using the factory pattern. This would save adding many if and try statements downstream.

@absurdfarce

Copy link
Copy Markdown
Contributor

@absurdfarce absurdfarce merged commit da026e7 into apache:master Jan 24, 2023
Lorak-mmk added a commit to Lorak-mmk/python-driver that referenced this pull request Mar 31, 2023
version 3.26.0

* tag '3.26.0' of https://github.com/datastax/python-driver: (22 commits)
  Release 3.26: changelog & version
  Going back to known good non-2.7 PyPy target.  PYTHON-1333 has more detail.
  Forgot to add complete extension
  Trying to get to a maximal working Pypy version.  Have to go back to 3.6 which isn't ideal...
  Update Travis config to only run versions that will be supported going forward
  Minor refactor of prior commit: now that we're dropping 2.7.x support we don't really need to leverage six for unit test functions.
  Remove references to unsupported Python versions from setup.py
  Refactor deprecated unittest aliases for Python 3.11 compatibility. (apache#1112)
  Merge pull request apache#1140 from python-driver/python-1327
  Merge pull request apache#1139 from python-driver/python-1328
  Merge pull request apache#1137 from python-driver/python-1329
  Merge pull request apache#1128 from python-driver/python-1304
  Fix jenkins builds (apache#1134)
  Minor refactor of prior commit
  Handle "log gone" case in the end of _run_loop (apache#1133)
  HostFilterPolicyInitTest fix for Python 3.11 (apache#1131)
  Groovy fixes
  Hey, let's actually update the right things, shall we?
  Smaller smoke test configuration to avoid explosion of test builds in AWS
  Fix to prior fix
  ...
Lorak-mmk added a commit to Lorak-mmk/python-driver that referenced this pull request Apr 12, 2023
version 3.26.0

* tag '3.26.0' of https://github.com/datastax/python-driver: (22 commits)
  Release 3.26: changelog & version
  Going back to known good non-2.7 PyPy target.  PYTHON-1333 has more detail.
  Forgot to add complete extension
  Trying to get to a maximal working Pypy version.  Have to go back to 3.6 which isn't ideal...
  Update Travis config to only run versions that will be supported going forward
  Minor refactor of prior commit: now that we're dropping 2.7.x support we don't really need to leverage six for unit test functions.
  Remove references to unsupported Python versions from setup.py
  Refactor deprecated unittest aliases for Python 3.11 compatibility. (apache#1112)
  Merge pull request apache#1140 from python-driver/python-1327
  Merge pull request apache#1139 from python-driver/python-1328
  Merge pull request apache#1137 from python-driver/python-1329
  Merge pull request apache#1128 from python-driver/python-1304
  Fix jenkins builds (apache#1134)
  Minor refactor of prior commit
  Handle "log gone" case in the end of _run_loop (apache#1133)
  HostFilterPolicyInitTest fix for Python 3.11 (apache#1131)
  Groovy fixes
  Hey, let's actually update the right things, shall we?
  Smaller smoke test configuration to avoid explosion of test builds in AWS
  Fix to prior fix
  ...
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.

3 participants