soheilhy / cmux

Connection multiplexer for GoLang: serve different services on the same port!
Apache License 2.0
2.57k stars 196 forks source link

How to serve gRPC + SSH with cmux? #44

Closed arkan closed 7 years ago

arkan commented 7 years ago

Hi,

I'm trying to use cmux to serve gRPC + SSH connections, but I cannot make it works.

lis, _ := net.Listen("tcp", ":8080")

l := cmux.New(lis)
grpcL := l.Match(cmux.HTTP2HeaderField("content-type", "application/grpc"))
sshL := l.Match(cmux.Any())

It serves gRPC well but it blocks when I connect with a ssh client.

If I comment the gRPC Match the SSH connections work. Am I doing something wrong?

Thanks

soheilhy commented 7 years ago

That's odd. I will have to take a look. Does your SSH connection send the HTTP2 preface?

On Fri, Apr 21, 2017 at 1:08 PM, Florian Bertholin <notifications@github.com

wrote:

Hi,

I'm trying to use cmux to serve gRPC + SSH connections, but I cannot make it works.

lis, _ := net.Listen("tcp", ":8080") l := cmux.New(lis)grpcL := l.Match(cmux.HTTP2HeaderField("content-type", "application/grpc"))sshL := l.Match(cmux.Any())

It serves gRPC well but it blocks when I connect with a ssh client.

If I comment the gRPC Match the SSH connections work. Am I doing something wrong?

Thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/soheilhy/cmux/issues/44, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYGhT5ZopypI92zlHuKuWhN2mDITSo9ks5ryOKlgaJpZM4NEjw3 .

arkan commented 7 years ago

Hey, thanks for the reply!

Here is what I have if I run the SSH command with -v:

$> ssh -v -p 8081 127.0.0.1
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/arkan/.ssh/config
debug1: /Users/arkan/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 8081.
debug1: Connection established.
debug1: identity file /Users/arkan/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/arkan/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4

And then the connection is blocked. If you need anything else let me know.

soheilhy commented 7 years ago

I think this is a cmux bug. Can you please try branch fix-44 to see if it fixes your issue and doesn't cause any other regressions for you? Thanks! https://github.com/soheilhy/cmux/tree/fix-44

arkan commented 7 years ago

Hey, I tried it out on my project and it seems to be working as expected :) Thanks for the patch.

soheilhy commented 7 years ago

Thanks for the confirmation.