Skip to content

Conversation

@mirelap-amazon
Copy link
Contributor

Running the uwsgi sample application with Python 3.8.10-3.9.2 showed incorrect module path in the UI.
This was narrowed down to traceback returning different results (a path with "/.").

This change makes sure the path is not leaked out.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Issue #, if available:

Description of changes:

Testing:
With this change, this is the logged module after removing the prefix :

  • with this change: INFO /polls/views.py
  • before this change for:
    --uwsgi: /Users/mirelap/Documents/workspace/JSON/aws-codeguru-profiler-python-demo-application/sample-demo-django-app//polls/viewspy
    --runserver: /polls/views.py

Before this change when running this sample app with uwsgi command (not with the local runserver) starting Python 3.8.10:
Screenshot 2021-06-21 at 11 21 29.

After this change:

Screenshot 2021-06-21 at 11 55 47

Running the uwsgi sample application with Python 3.8.10-3.9.2 showed incorrect module path in the UI.
This was narrowed down to traceback returning different results (a path with "/.").

This change makes sure the path is not leaked out.
@mirelap-amazon mirelap-amazon requested review from a team and PapaPedro June 21, 2021 10:56
@mirelap-amazon mirelap-amazon self-assigned this Jun 21, 2021
Copy link
Contributor

@PapaPedro PapaPedro left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a few comments/questions

def _remove_prefix_path(module_path, sys_paths):
current_path = str(Path().absolute())
if current_path in module_path:
return module_path.replace(current_path, "").replace("/.", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not replace "/./" by "/" ?

Copy link
Contributor

Choose a reason for hiding this comment

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

also that would not work in windows because the "/" would have been replaced already right? Are we sure we cannot have that problem in windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds better to replace /./, I'll update. I didn't test anything on windows. The existing unit tests with Windows passed, but I didn't add anything new.

Comment on lines 90 to 95
# When running the sample app with uwsgi for Python 3.8.10-3.9.2, the traceback command
# returns a file path that contains "/.".
# To not let the path go into the module name, we are removing it later in the ProfileEncoder.
# Examples:
# - file '/Users/mirelap/Documents/workspace/JSON/aws-codeguru-profiler-python-demo-application/sample-demo-django-app/./polls/views.py', line 104, code get_queryset>, 104
# - file '/Users/mirelap/Documents/workspace/JSON/aws-codeguru-profiler-python-demo-application/sample-demo-django-app/polls/views.py', line 104, code get_queryset>, 104
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment seems to be very specific about the /./ problem but is not next to the code that actually fixes this issue, should we not simply add a comment here saying only that the full path will be removed from frame names later in the encoder and only talk about the /./ issue when we do the replace about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I'll update.

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