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

Add callback/hook when the client connection is closed #225

Open
adiroiban opened this issue May 5, 2021 · 0 comments
Open

Add callback/hook when the client connection is closed #225

adiroiban opened this issue May 5, 2021 · 0 comments

Comments

@adiroiban
Copy link
Member

I am running some automated end to end tests with ldaptor client-side.

My code runs a set of LDAP operation and at the end of each test the connection to the LDAP server is closed.

At the end of each test, I have some extra checks that no connections are accidentally left open and that the reactor is clean.

I used to have this final Deferred.addBoth that will forward the result but will close the client connection.

        def bb_connect_done(result, client):
            """
            Called after all LDAP operations to clean the client.
            """
            if client.connected:
                client.unbind()

            return result

The problem is the client.unbind() is not returning a deferred. Just triggering a transport.loseConnection and hoping for the best :)

This is not a big problem for TCP, but for TLS the TLS shutdown might take a bit longer.

for now, as a workaround I am using this hack ... triggering a disconnection and then calling bind right away to put a request on the wire that will errback when the connection is actually lost.

        def bb_connect_done(result, client):
            """
            Called after all LDAP operations to clean the client.
            """
            if client.connected:
                client.unbind()

            deferred = client.bind(b'', b'')
            deferred.addBoth(lambda _: result)
            return deferred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant