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

address #279: allow for parallel processing of handshakes #613

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jordan-bonecutter
Copy link

Description

To allow for parallel handshake processing, I propose to introduce the AcceptHandshake method on listener. AcceptHandshake returns a Handshaker interface, which is just a conn who has not yet performed their handshake and a config for doing so. Handshakes may be processed in parallel by calling the Handshake method on the Handshaker in a background goroutine.

Reference issue

Fixes #279

@daenney
Copy link
Member

daenney commented Mar 18, 2024

Thanks for the proposed change. I'm not sure about the Handshake interface, but either way we'd need to at least also have tests, and ideally an example that shows/documents how to use it.

@jordan-bonecutter
Copy link
Author

jordan-bonecutter commented Mar 18, 2024

Thanks for the proposed change. I'm not sure about the Handshake interface, but either way we'd need to at least also have tests, and ideally an example that shows/documents how to use it.

Definitely, didn't want to go too far down the rabbit hole if people didn't like the change. I'll spend some time making a test today. I can make an example as well.

The basic idea (if unclear) is that before one would do:

conn, err := ln.Accept()
if err != nil {
  return err
}
go handleConn(conn)

Now, one may do:

hs, err := ln.AcceptHandshake()
if err != nil {
  return err
}
go handleHandshaker(hs)

func handleHandshaker(hs Handshaker) {
  conn, err := hs.Handshake()
  if err != nil {
    return
  }
  handleConn(conn)
}

The only annoying thing is that the AcceptHandshake method won't be exported, so it'll require a type assertion unless a different type with this method exported is returned.

@jordan-bonecutter
Copy link
Author

@daenney I've added a test + example. Let me know what needs changing, thanks!

@daenney
Copy link
Member

daenney commented Mar 19, 2024

@Sean-Der Care to take a look? This has come up before and it might just be nice to fix it. It's a backwards compatible change since folks can upgrade to the proposed Handshake method of doing it. I know we've discussed something similar to this at some point for a v3 too.

@jordan-bonecutter
Copy link
Author

@daenney bump on this. Anything I can do to speed up the process?

@daenney
Copy link
Member

daenney commented Apr 1, 2024

No not really, things take time as we're all unpaid volunteers. A few other maintainers need to take a look, as adding new APIs has long-term-ish consequences. I'd want us to agree on an API we would also be happy with for v3, so if users switch we don't break them all over again.

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

Successfully merging this pull request may close these issues.

Listener doesn't process parallel handshakes
2 participants