Enabled logging of failed port bind (v2)#490
Conversation
…` to aid in debugging application bind failures. See Pylons#471
kgaughan
left a comment
There was a problem hiding this comment.
Some immediate comments. I need to take a look over a few other things too though.
kgaughan
left a comment
There was a problem hiding this comment.
Almost there! There's some bit of leakage between the tests due to the redundant handling of self.inst and self.insts: by getting everything to use just self.insts, We should end up with everything properly cleaned up between tests. Hopefully I haven't missed anything!
tests/test_server.py
Outdated
| # most tests only start a single server | ||
| if self.inst is not None: | ||
| self.inst.close() | ||
|
|
There was a problem hiding this comment.
I don't think you need this: the for loop should already be handling that if you update _makeOneWithMulti and _makeOneWithSockets to push onto self.insts. Also, it's potentially closing at least one of the instances twice as the last instance in self.insts created by self._makeOne will be the same as what's in self.inst.
tests/test_server.py
Outdated
There was a problem hiding this comment.
I think we only really need self.insts, so...
| inst = create_server( |
tests/test_server.py
Outdated
| self.insts.append(self.inst) | ||
| return self.inst |
There was a problem hiding this comment.
...and:
| self.insts.append(self.inst) | |
| return self.inst | |
| self.insts.append(inst) | |
| return inst |
Nothing outside of the constructor, tearDown, and the _makeOne* methods need to access any of this, so using self.insts for everything keeps cleanup more straighforward.
tests/test_server.py
Outdated
There was a problem hiding this comment.
Same again:
| inst = create_server( |
tests/test_server.py
Outdated
There was a problem hiding this comment.
| self.insts.append(inst) | |
| return inst |
tests/test_server.py
Outdated
There was a problem hiding this comment.
| inst = create_server( |
tests/test_server.py
Outdated
| @@ -91,9 +110,15 @@ def _makeWithSockets( | |||
| return self.inst | |||
There was a problem hiding this comment.
| return self.inst | |
| self.insts.append(inst) | |
| return inst |
tests/test_server.py
Outdated
| if self.insts: | ||
| for inst in self.insts: | ||
| inst.close() |
There was a problem hiding this comment.
This if statement is redundant: the for loop won't run its contents if there's nothing in the list.
Doing self.insts = [] after the loop to prevent bleed-over between tests.
| if self.insts: | |
| for inst in self.insts: | |
| inst.close() | |
| for inst in self.insts: | |
| inst.close() | |
| self.insts = [] |
tests/test_server.py
Outdated
| inst.close() | ||
|
|
||
| def test_ctor_app_is_None(self): | ||
| self.inst = None |
There was a problem hiding this comment.
| self.inst = None | |
| self.insts = [] |
There was a problem hiding this comment.
We can just drop this line, as the init sets this up already.
tests/test_server.py
Outdated
| # most tests only start a single server (for cleanup) | ||
| inst: Union["BaseWSGIServer", "MultiSocketServer", None] | ||
|
|
There was a problem hiding this comment.
With the rest of the suggested changes, this is now redundant.
|
Ok. I'm absolutely down to replace everything with self.insts . I'll get through these on my next free block today. |
tests/test_server.py
Outdated
There was a problem hiding this comment.
Ah! Spotted one place. Using self.inst here doesn't even really make sense.
| inst = WSGIServer(None, _start=False, port=1234) | |
| try: | |
| # Ensure the adjustment was actually applied. | |
| self.assertNotEqual(Adjustments.port, 1234) | |
| self.assertEqual(inst.adj.port, 1234) | |
| finally: | |
| inst.close() |
|
I'm trying to figure out where/how there is an unclosed socket in warnings. |
|
Ok, the leak is due to #480. I thought this test case could be used to surface it the other day, and I was right. When creating it is because the logic in I added some docstrings to this test; they can be cross-referenced into the other ticket. I think a future PR to fix that behavior could leverage this test. |
This PR enables logging on failed port binds. See #471
This is a continuation of #489 ; my git checkout got messed up. (While fixing some artifacts from merging to main, I accidentally named a new working branch from
origin/feature-log_bind_failuresinstead of origin'sfeature-log_bind_failures)