Coder Social home page Coder Social logo

Close connections gracefully. about hyper HOT 2 OPEN

python-hyper avatar python-hyper commented on July 18, 2024
Close connections gracefully.

from hyper.

Comments (2)

jdecuyper avatar jdecuyper commented on July 18, 2024

Hi @Lukasa!

Spec says: Endpoints SHOULD send a GOAWAY frame when ending a connection, providing that circumstances permit it.

So when shutting down gracefully we need to call close on all streams and then send a final GoAway frame on the connection control stream, something like:

# Close all streams
for stream in list(self.streams.values()):
   print("Closing stream with id %d" % stream.stream_id)
   stream.close()

# Send GoAway frame to the server
   self._send_cb(GoAwayFrame(0), True)

I think we should also close the stream for connection control with id 0, but I'm not sure yet where it is.

On a related matter, the spec also says An endpoint that receives an unexpected stream identifier MUST respond with a connection error (Section 5.4.1) of type PROTOCOL_ERROR. I don't think we are validating if the stream identifier actually exists or not on the client side. Code looks as follow right now:

self.streams[frame.stream_id].receive_frame(frame)

I guess we should validate first if this stream_id exists inside the streams collection, right?

from hyper.

Lukasa avatar Lukasa commented on July 18, 2024

I think we should also close the stream for connection control with id 0, but I'm not sure yet where it is.

Stream zero always exists, and there is no need to explicitly close it.

I guess we should validate first if this stream_id exists inside the streams collection, right?

A try...except block would be better style, but yes. =)

So when shutting down gracefully we need to call close on all streams and then send a final GoAway frame on the connection control stream

Sounds like a good idea to me!

from hyper.

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.