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

Fix error "[Errno 111] Connection refused" and make logs more usable #1029

Merged
merged 3 commits into from
May 11, 2020

Conversation

MVrachev
Copy link
Collaborator

@MVrachev MVrachev commented May 5, 2020

Fixes issue #: #1010

Description of the changes being introduced by the pull request:
When running the tests this error appears
"[Errno 111] Connection refused". After some digging Lukas
found another error "No module named tests.simple_server"
which is the root cause for error 111.

With the help of Joshua Lock, we found out that the simple_server.py
was not being found because of subprocess.Popen was being passed
a cwd kwarg which moved the current working directory
away from tuf/tests.
That's what I fix with the first commit.

In my second commit, I remove stderr=subprocess.PIPE argument from subprocess.Popen function calls and make the QuietHTTPRequestHandler as the default HTTP handler in the simple_server.py script.
This change is inspired by the digging needed to discover the real problem causing issue 1010 summarized well in the @lukpueh comment #1010 (comment).

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

@MVrachev MVrachev changed the title Fix 1010 Fix error "[Errno 111] Connection refused" and make logs more usable May 5, 2020
Copy link
Contributor

@mnm678 mnm678 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, this looks good to me.

@joshuagl will the calls to os.getcwd() be affected by the abstract file system work in #1024?

Copy link
Member

@joshuagl joshuagl left a comment

Choose a reason for hiding this comment

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

Thanks for the solid changes to fix this issue @MVrachev.

A few minor suggestions and this is good to go:

  • We only need the change to invoke simple_server.py with cwd for tests/test_multiple_repositories_integration.py and tests/test_updater.py – could you restore the other tests to their current behaviour of just calling simple_server.py ?
  • I added some comments to simple_server.py itself to keep that code short and idiomatic, could you please address those?

Thanks

if len(sys.argv) > 2:
use_quiet_http_request_handler = sys.argv[2]

if use_quiet_http_request_handler == True:
Copy link
Member

Choose a reason for hiding this comment

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

As this is Python and we expect a boolean value we can just test the variable like:

Suggested change
if use_quiet_http_request_handler == True:
if use_quiet_http_request_handler:

See PEP 8's Programming Recommendations and the Book of Python Anti-Patterns

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, I just wanted to be more explicit, but you are right.
I will address this.

Comment on lines 70 to 72
# server on those Windows/Py2 to not fill the buffer.
if six.PY2 and platform.system() == 'Windows':
handler = QuietHTTPRequestHandler
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we still need this logic above if we now default to using QuietHTTPRequestHandler? Certainly we don't want two ways to change the HTTP Request Handler for this simple test server.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't want to remove this check so that this strange case for Windows is documented.

If I remove it now and someone change this piece of code again this bug can reappear.

Copy link
Member

Choose a reason for hiding this comment

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

I can see the logic in that, we can either leave the comment and remove the code or consolidate this logic with your change. We should absolutely not set the handler in two places which can conflict with each other. As it stands if I explicitly set use_quiet_http_request_handler = False on Windows, I still get QuietHTTPRequestHandler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you are right. I will group those checks together so that we don't change the state in two places.

I am wondering which should be with higher priority: use_quiet_http_request_handler value or the check if we are on Windows?
I think that if we are on Windows should be with higher priority given that we have bug reported for that specific case.

@joshuagl
Copy link
Member

joshuagl commented May 5, 2020

@joshuagl will the calls to os.getcwd() be affected by the abstract file system work in #1024?

No, these calls are restricted to test code and are to ensure that we have the tests/ directory in order to a) serve the test repo data and b) ensure we are invoking simple_server.py in a way which won't cause errors when there are multiple tests/ directories in the PYTHONPATH (as is the case when we're running with editable securesystemslib and editable tuf installations).

Fixes issue: theupdateframework#1010

When running the tests this error appears
"[Errno 111] Connection refused". After some digging Lukas
found another error "No module named tests.simple_server"
which is the root case for error 111.

With the help of Joshua Lock, we found out that the simple_server.py
was not being found because subprocess.Popen was being passed
a cwd kwarg which moved the current working directory
away from tuf/tests.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Passing a pipe to the subprocess, but not reading from it
conceals helpful error messages.
As the code redirects all of the stderr from the subprocess
to nowhere, the error output of the process is never read.
If we remove the PIPEs from the tests we should see some
error messages on the console/logger that can
help us understand what went wrong.

On another hand, when we stop passing stderr=subprocess.PIPE arg
to the subprocess.Popen function call there are a lot of
HTTP messages together with the helpful error messages.
One decision is to make QuietHTTPRequestHandler
the default. That way we receive the helpful error messages
without the HTTP messages.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
@MVrachev
Copy link
Collaborator Author

MVrachev commented May 7, 2020

  • We only need the change to invoke simple_server.py with cwd for tests/test_multiple_repositories_integration.py and tests/test_updater.py – could you restore the other tests to their current behaviour of just calling simple_server.py ?

Yes, you are right. I updated my pr with the above suggestions and the ones left alongside the code.

After a discussion with Joshua Lock, we agreed that for
Windows users it would be good to provide the option to use
SimpleHTTPRequestHandler, but still leave a warning about it,
knowing that this caused an error before.
See: theupdateframework@7dbb30a

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Copy link
Member

@joshuagl joshuagl left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @MVrachev! Great to have this issue resolved. 🎉

@joshuagl joshuagl merged commit d7aec6a into theupdateframework:develop May 11, 2020
@MVrachev MVrachev deleted the fix-1010 branch August 4, 2020 10:27
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