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

asyncore doesn't handle connection refused correctly #47193

Closed
shigin mannequin opened this issue May 22, 2008 · 18 comments
Closed

asyncore doesn't handle connection refused correctly #47193

shigin mannequin opened this issue May 22, 2008 · 18 comments
Assignees
Labels
release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@shigin
Copy link
Mannequin

shigin mannequin commented May 22, 2008

BPO 2944
Nosy @loewis, @warsaw, @josiahcarlson, @giampaolo, @bitdancer, @intgr
Files
  • test_async_connect.py: simple test example, it works only if none listens on port 9090
  • asyncore-connect-patch.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/giampaolo'
    closed_at = <Date 2010-08-13.08:50:17.601>
    created_at = <Date 2008-05-22.13:23:58.372>
    labels = ['type-bug', 'library', 'release-blocker']
    title = "asyncore doesn't handle connection refused correctly"
    updated_at = <Date 2010-08-14.00:46:44.311>
    user = 'https://bugs.python.org/shigin'

    bugs.python.org fields:

    activity = <Date 2010-08-14.00:46:44.311>
    actor = 'barry'
    assignee = 'giampaolo.rodola'
    closed = True
    closed_date = <Date 2010-08-13.08:50:17.601>
    closer = 'loewis'
    components = ['Library (Lib)']
    creation = <Date 2008-05-22.13:23:58.372>
    creator = 'shigin'
    dependencies = []
    files = ['10400', '10856']
    hgrepos = []
    issue_num = 2944
    keywords = ['patch']
    message_count = 18.0
    messages = ['67188', '67189', '67196', '67306', '67308', '69427', '74125', '74127', '112704', '112775', '113707', '113709', '113710', '113715', '113730', '113733', '113735', '113857']
    nosy_count = 9.0
    nosy_names = ['loewis', 'barry', 'josiahcarlson', 'forest', 'giampaolo.rodola', 'josiah.carlson', 'shigin', 'r.david.murray', 'intgr']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2944'
    versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']

    @shigin
    Copy link
    Mannequin Author

    shigin mannequin commented May 22, 2008

    Unix select returns socket in read fd set and write fd set if
    nonblocking socket attempts to connect to unaviable address.

    asyncore should check this case by calling getsockopt with SO_ERROR
    optname. If return value is 0 it should call handle_connect_event,
    otherwise if should call handle_expt_event.

    Attached file prints "get exception" if asyncore can't connect to
    remote side, not "uncaptured python exception"

    Patches from bpo-1736190 do not fix this case.

    @shigin shigin mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 22, 2008
    @shigin
    Copy link
    Mannequin Author

    shigin mannequin commented May 22, 2008

    Patch against r63534 fix the issue.

    @shigin
    Copy link
    Mannequin Author

    shigin mannequin commented May 22, 2008

    Oh, I've just realised that FreeBSD is too fast. test_async_connect.py
    works fine on linux box, but on FreeBSD i need to change localhost to
    another host :(

    I haven't got any idea how to make a test case which work on any
    machine.

    @giampaolo
    Copy link
    Contributor

    By trying your script on Linux and Windows I notice different behaviors.
    On Windows handle_expt is always called.
    On Linux, no matter if using select or poll, handle_accept is called,
    then an exception is thrown at the time the data is going to be sent:

    Traceback (most recent call last):
      File "index.py", line 34, in <module>
        test()
      File "index.py", line 31, in test
        asyncore.loop(use_poll=1)
      File "/usr/lib/python2.5/asyncore.py", line 205, in loop
        poll_fun(timeout, map)
      File "/usr/lib/python2.5/asyncore.py", line 190, in poll2
        readwrite(obj, flags)
      File "/usr/lib/python2.5/asyncore.py", line 101, in readwrite
        obj.handle_error()
      File "/usr/lib/python2.5/asyncore.py", line 93, in readwrite
        obj.handle_read_event()
      File "/usr/lib/python2.5/asyncore.py", line 400, in handle_read_event
        self.handle_connect()
      File "index.py", line 17, in handle_connect
        self.send("hello world")
      File "/usr/lib/python2.5/asyncore.py", line 481, in send
        self.initiate_send()
      File "/usr/lib/python2.5/asyncore.py", line 468, in initiate_send
        num_sent = dispatcher.send(self, self.out_buffer[:512])
      File "/usr/lib/python2.5/asyncore.py", line 345, in send
        result = self.socket.send(data)
    socket.error: (111, 'Connection refused')

    In my opinion both behaviors are wrong since neither handle_expt nor
    handle_connect should be called in case of a "connection refused" event.
    Especially handle_connect should not be called at all since no
    connection takes place.
    The correct behavior here must be identifying when such event occurs,
    raise the proper exception (ECONNREFUSED) and let it propagate until
    handle_error which will take care of it.

    @shigin
    Copy link
    Mannequin Author

    shigin mannequin commented May 24, 2008

    Oh, fine. May be handle_error should have been called, but anyway not
    handle_connect.

    But in my mind, handle_expt is better.

    @shigin
    Copy link
    Mannequin Author

    shigin mannequin commented Jul 8, 2008

    Here is a new patch against r64768

    The new patch raise an exception if asynchronous connect fails.

    @giampaolo
    Copy link
    Contributor

    This should have already been fixed in r64062.

    @shigin
    Copy link
    Mannequin Author

    shigin mannequin commented Oct 1, 2008

    I've got the same error in r64768.

    @giampaolo
    Copy link
    Contributor

    Assigning this to me. The patch looks correct, it only needs tests assuming it is possible to write a reliable test for this.

    @giampaolo giampaolo self-assigned this Aug 3, 2010
    @giampaolo
    Copy link
    Contributor

    Fixed in r83703 (2.7), r83704 (2.6), r83705 (3.2) and r83706 (3.1).
    Thanks for the patch.

    @warsaw
    Copy link
    Member

    warsaw commented Aug 12, 2010

    The fix for this was applied after 2.6.6rc1, and it wasn't approved by me. Is it critical for 2.6? Is it a regression since 2.6.5? The way I see it, we either back this out or release an rc2. There may be other reasons to release an rc2, but I need to verify that that is possible for MvL.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Aug 12, 2010

    What date would the final release then be made? It would be best if it could be done before Aug 27. If necessary, I could also make a release on September 6 (but not any day before or after)

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Aug 12, 2010

    The bug is not a regression since 2.6.5; AFAICT, it was in Python "forever". I recommend to revert the checkin, and postpone fixing it to 2.7.1.

    @warsaw
    Copy link
    Member

    warsaw commented Aug 12, 2010

    I agree w/mvl. Giampaolo, please revert this for 2.6.6.

    @giampaolo
    Copy link
    Contributor

    The commit was made on August 04, 11:05 AM, while rc1 was released at 06:09 PM.
    I don't think the patch is going to introduce any problem but if you think it's the case to revert it then I'll do it.

    @bitdancer
    Copy link
    Member

    The question isn't when it was released, but when it was tagged, and that happened at Aug 3 22:51:57 2010 UTC according to svn. Your commit was made Aug 4 08:58:38 2010 UTC.

    @giampaolo
    Copy link
    Contributor

    Ok, no problem. Reverted in r83969.

    @loewis loewis mannequin closed this as completed Aug 13, 2010
    @warsaw
    Copy link
    Member

    warsaw commented Aug 14, 2010

    Just to close the loop: thanks for reverting this for 2.6.6!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants