Skip to content

bpo-33099: Fix test_poplib hangs after error#6428

Closed
methane wants to merge 5 commits into
python:masterfrom
methane:test_poplib-hang
Closed

bpo-33099: Fix test_poplib hangs after error#6428
methane wants to merge 5 commits into
python:masterfrom
methane:test_poplib-hang

Conversation

@methane

@methane methane commented Apr 9, 2018

Copy link
Copy Markdown
Member

This fixes resource leaks in the test and reveals real errors.

https://bugs.python.org/issue33099

This fixes resource leaks in the test and reveals real errors.

@tiran tiran left a comment

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.

Please convert try / bare except to try/finally and remove the print_exc line. The same fix should be applied to other tests that use asyncore (ftplib, smtplib, smtpd?)

Comment thread Lib/test/test_poplib.py Outdated
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3)
try:
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3)
except:

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.

This should be try/finally.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

When setUp() succeeded, tearDown() do it.
So this should be except:, not finally:.

Comment thread Lib/test/test_poplib.py Outdated
self.client = poplib.POP3_SSL(self.server.host, self.server.port)
try:
self.client = poplib.POP3_SSL(self.server.host, self.server.port)
except:

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.

try/finally

Comment thread Lib/test/test_poplib.py Outdated
try:
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3)
self.client.stls()
except:

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.

try/finally

Comment thread Lib/test/test_poplib.py Outdated
try:
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3)
except:
traceback.print_exc()

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.

Why did you add print_exc?

@bedevere-bot

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Comment thread Lib/test/test_poplib.py
try:
self.client = poplib.POP3(self.server.host, self.server.port, timeout=3)
except:
self.server.stop()

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.

Can self.server.stop() fail? Is it worth to rewrite the code as:

try:
    self.server.stop()
finally:
    self.server = None
    raise

or

server = self.server
self.server = None
server.stop()
raise

?

Copy link
Copy Markdown
Member Author

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 shouldn't complicate test code for non-real errors.
It's not late to fix it after the possibility become real.

@methane

methane commented Apr 9, 2018

Copy link
Copy Markdown
Member Author

"I have made the requested changes; please review again."

@tiran I added same cleanup to test_os and test_ftplib.
test_smtplib and test_smtpd has different architecture. They don't use server threads. So they must not hang for dangling threads.

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@tiran: please review the changes made to this pull request.

@methane

methane commented May 28, 2018

Copy link
Copy Markdown
Member Author

Same fix is commited via #6865.

@methane methane closed this May 28, 2018
@methane methane deleted the test_poplib-hang branch July 23, 2018 08:27
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.

5 participants