Giter Site home page Giter Site logo

Comments (5)

andrewgodwin avatar andrewgodwin commented on June 18, 2024

I'm shocked we never specified this to be honest - you'd think it would have come up before now!

I'm inclined to say that an exception is the best behaviour here, as silent failure sending things down a socket seems like a way to make people's debugging very annoying. I can think of other behaviours when this might occur, though - HTTP connections where you try to send some body after sending previous body with more_body=False.

Probably makes the most sense to define a common error type that gets raised in these scenarios? We could define one in asgiref, but that kind of irks me as it means you'd need the package to implement the spec, whereas right now you don't. Maybe just saying you get something like IOError would be better.

from asgiref.

Kludex avatar Kludex commented on June 18, 2024

I'm shocked we never specified this to be honest - you'd think it would have come up before now!

It actually came up some years ago in the FastAPI discussions. I didn't know enough by then. 😁

HTTP connections where you try to send some body after sending previous body with more_body=False.

Hmm... I didn't understand this case - or how it's similar to the current.

Probably makes the most sense to define a common error type that gets raised in these scenarios? We could define one in asgiref, but that kind of irks me as it means you'd need the package to implement the spec, whereas right now you don't.

This seems like it will create a barrier for package maintainers to be fully compliant with ASGI.

Maybe just saying you get something like IOError would be better.

Yes, it will. But... Can we be more generic here instead? Would it be bad to write something like the following?

The `send` event may raise an `Exception` in case the client is disconnected.

Maybe even... (to be improved)

The ASGI framework should be in charge of catching the exception.

from asgiref.

Kludex avatar Kludex commented on June 18, 2024

I had an idea!

What if we enable the application and the server to communicate about those scenarios beforehand?

One way could be being an ASGI extension:

"scope": {
    ...
    "extensions": {
        "websockets.send.exceptions": {
            "exceptions": [
                 websockets.WebSocketException,
                 wsproto.LocalProtocolError,
             ]
         },
    },
}

Details, and API to be defined (it can be more generic, more specific), but you get the idea.

from asgiref.

Kludex avatar Kludex commented on June 18, 2024

Well... I see that @tomchristie created an issue here about WebSocket.send exceptions years ago: #66. 😅

from asgiref.

Kludex avatar Kludex commented on June 18, 2024
  • I'm going to close this in favor of #66.

from asgiref.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.