Skip to content

[py] Log complete python errors + tracebacks when check import fails#259

Merged
truthbk merged 2 commits intomasterfrom
olivielpeau/complete-py-tracebacks
May 21, 2017
Merged

[py] Log complete python errors + tracebacks when check import fails#259
truthbk merged 2 commits intomasterfrom
olivielpeau/complete-py-tracebacks

Conversation

@olivielpeau
Copy link
Copy Markdown
Member

What does this PR do?

In some cases the python module of a check can't be imported because
of a python code issue, in that case logging the traceback is useful. This PR
does just that.

Motivation

Without this change it's impossible to debug an issue with the import of a python
check module, based on the logs alone.

Additional Notes

Use a common function that retrieves and formats the python
interpreter error, and clears the error flag in the interpreter.
Any python c api call that returns an error should be followed by
a call of that common function to get a formatted string of the error.

The signature of that function could be changed at some point to return
something more meaningful than just a string, but I didn't feel the need for that
right now.

In some cases the python module of a check can't be imported because
of a python code issue, in that case logging the traceback is useful.

Use a common function that retrieves and formats the python
interpreter error, and clears the error flag in the interpreter.
Any python c api call that returns an error should be followed by
a call of that common function to get a formatted string of the error.
Comment thread pkg/collector/py/utils.go Outdated
// getPythonError returns string-formatted info about a Python interpreter error that occurred,
// and clears the error flag in the Python interpreter
func getPythonError() (string, error) {
gstate := NewStickyLock()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can't remember off the top of my head if this was safe. As the reviewer I should make sure, but until I do, this could be a deadlock situation here.

Copy link
Copy Markdown
Member

@truthbk truthbk May 18, 2017

Choose a reason for hiding this comment

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

This is fine on the python side... but there could be collateral:gstate python.PyGILState can be called with python.PyGILState_Ensure() multiple times, as per the python docs (https://docs.python.org/2/c-api/init.html#c.PyGILState_Ensure). However, as we just discussed offline, there's an underlying problem:

When we make nested calls to StickyLock(), we will "lock" the goroutine to a thread, and there should be no problem in doing this twice. But during the unlocking, when the nested function unlocks, it will call runtime.UnlockOSThread(), and at that point the goroutine will be preemptible from the current thread and could potentially change to a different one (with the known ugly sideeffects).

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.

The StickyLock is not meant to be called more than once so it shouldn't be nested.

Copy link
Copy Markdown
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

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

Let's remove the nested lock for now, until we find an elegant way of dealing with this. We should also create an issue to look into this carefully.

Using a nested lock unlocks to goroutine to the thread when the child
lock is unlocked (whereas we'd want that to happen when the parent lock
is unlocked).

Until we can figure out a good way to deal with this situation, don't
use nested locks, and add a warning to `getPythonError`.
@olivielpeau
Copy link
Copy Markdown
Member Author

Thanks @truthbk for pointing this out, I've updated the code to not use nested locks

@masci masci mentioned this pull request May 19, 2017
@truthbk truthbk merged commit 0dd9a26 into master May 21, 2017
@masci masci deleted the olivielpeau/complete-py-tracebacks branch May 21, 2017 07:15
s-alad pushed a commit that referenced this pull request Jan 6, 2026
Bumps [github.com/aws/aws-sdk-go-v2/service/secretsmanager](https://github.com/aws/aws-sdk-go-v2) from 1.39.13 to 1.40.1.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json)
- [Commits](aws/aws-sdk-go-v2@service/sfn/v1.39.13...service/s3/v1.40.1)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/service/secretsmanager
  dependency-version: 1.40.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

3 participants