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

on_unsubscribe: asyncio.CancelledError when http_post() #59

Open
inschiavon opened this issue Dec 18, 2020 · 0 comments
Open

on_unsubscribe: asyncio.CancelledError when http_post() #59

inschiavon opened this issue Dec 18, 2020 · 0 comments

Comments

@inschiavon
Copy link

inschiavon commented Dec 18, 2020

Hello, first of all, thanks for this magnificent library.

We have found an issue during the 'authorization_renewal_period'.

Summary

When the authorisation expires and, then, the authorisation is not valid, an on_unsuscribe event should be sent but our hook handler (our server) is not able to receive the request.

What we saw in the code

When the event of unsuscribing is happening and tries to send an http_post to the hook, there is an exception which is not handled: asyncio.CancelledError

What we did to fix it

We added a catch exception code block:

except asyncio.CancelledError:
    log.exception('Task was cancelled')

What was the behaviour after the fix

In the first try to run the function, it throws an exception and the try-catch block avoids finishing the execution
As it has a retry functionality, in the second try, the http post is sent to the hook and the client correctly receives the message indicating the unsubscription.

Where we saw it

How to replicate the issue:

  • Set a websocket config with and authorizer and authorization_renewal_period

E.g.

    'myservice': {
        'require_authentication': True,
        'authorizer': 'myhost/websocket/authorize/',
        'authorization_renewal_period': 10,
        'on_subscribe': 'myhost/websocket/on_subscribe/',
        'on_unsubscribe': 'myhost/websocket/on_unsubscribe/',
    }

  • Run the server
  • Run a websocket client, connect and authorise your client. The authorisation should eventually expire.
{
    "event": "auth",
    "method": "ticket",
    "ticket": "ticketxxx"
}

  • Subscribe the client to the service
{
    "event": "subscribe",
    "subscription": "myservice",
}

  • Wait until your subscription expires.

  • Then, when the authorization expires.

  • The authorization_renewal_period process should catch this expiration and start its process.

  • Socketshark tries to send:

{"pid": xx, "url": "http://myhost/websocket/on_unsubscribe/", "data": {"subscription": "myservice", ...}, "event": "http request", "level": "debug", "logger": "socketshark", "timestamp": "2020-12-18T13:09:58.012525Z"}

but as I mentioned before, myhost never receives the request due to the asyncio.CancelledError not handled.

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