Skip to content

socket.connect_ex returns None instead of 0 for successful connection #696

@Skyline124

Description

@Skyline124

Hello all,

I am developing a Flask application, served in production by gunicorn with the eventlet as worker.

At some point I am using the socket.socket.connect_ex function that returns an error code, rather than the socket object returned by the connect function: connect_ex documentation. The connect_ex returns 0 when the connection is successful.

When I am debugging my application, I run the Werkzeug WSGI implementation, with the 'regular' socket from the python library. So far so good.

When I am in production, I greenify the python library with the monkey_patch, and it replaces the socket object with the eventlet implementation of the socket. However, the behavior is different from the regular library, because when the connection succeeds, the eventlet implementation returns None and breaks my previously functioning code.

This can be seen on the line 277 of the file greenio/.base.py:277

A simple fix that seems to work for me would just to add a return 0 after the call of the function socket_checkerr(fd)

Do you think this is a reasonable patch? Or returning None is a desired behavior for some shady reason I am not aware of?

Thanks for reading me!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions