This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: socket close fixed
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: exarkun, facundobatista, hdiwan650, jyasskin
Priority: normal Keywords: patch

Created on 2007-07-30 06:38 by hdiwan650, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
socket.pat hdiwan650, 2007-07-30 06:38 Patch to Revision 56608
Messages (5)
msg52963 - (view) Author: Hasan Diwan (hdiwan650) Date: 2007-07-30 06:38
Patch fixes the race condition causing tests to mysteriously fail.
msg52964 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2007-07-30 10:06
SO_REUSEADDR is a flag.  It's not a period of time measured in seconds.  So using it with time.sleep() is conceptually broken, even though it happens to do something without raising an exception.

And socket.close() really, really, really should not sleep for any length of time at all.  It does what it needs to do by making the low-level call, and then it can return.  If the port shouldn't be re-used for some period of time, that is up to the application using the socket to deal with.

Since this ticket doesn't actually explain what the test failures _are_, I can't really suggest an alternate solution.  I assume it is something to do with binding to ports failing, though.  In this case, the tests should just be changed to bind port 0, which will force the platform to select an unused port.
msg52965 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2007-07-30 13:28
This patch

  a) does not address the problem that appeared in the tests (it should be solved in a very different way)
  b) as kuran correctly says, is conceptually wrong (see his comment)

Regards,
msg52966 - (view) Author: Jeffrey Yasskin (jyasskin) * (Python committer) Date: 2007-08-05 01:04
On OSX, I've seen both:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/Users/jyasskin/src/python/test_asyncore/Lib/threading.py", line 464, in __bootstrap
    self.run()
  File "/Users/jyasskin/src/python/test_asyncore/Lib/threading.py", line 444, in run
    self.__target(*self.__args, **self.__kwargs)
  File "Lib/test/test_asyncore.py", line 59, in capture_server
    serv.bind(("", PORT))
  File "<string>", line 1, in bind
socket.error: (48, 'Address already in use')

after which the interpreter freezes, and

======================================================================
ERROR: test_send (__main__.DispatcherWithSendTests_UsePoll)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_asyncore.py", line 351, in test_send
    d.send(data)
  File "/Users/jyasskin/src/python/test_asyncore/Lib/asyncore.py", line 467, in send
    self.initiate_send()
  File "/Users/jyasskin/src/python/test_asyncore/Lib/asyncore.py", line 454, in initiate_send
    num_sent = dispatcher.send(self, self.out_buffer[:512])
  File "/Users/jyasskin/src/python/test_asyncore/Lib/asyncore.py", line 334, in send
    if why[0] == EWOULDBLOCK:
TypeError: 'error' object is unindexable


I plan to fix the first by binding to port 0 as kuran suggested and using .getsockname()[1] to retrieve the port number, and the second by figuring out the right way to get the errno out of a socket.error.
msg52967 - (view) Author: Jeffrey Yasskin (jyasskin) * (Python committer) Date: 2007-08-05 01:08
Forgot to mention, this is on the p3yk branch. I don't know if it affects the trunk.
History
Date User Action Args
2022-04-11 14:56:25adminsetgithub: 45255
2007-07-30 06:38:00hdiwan650create