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

Dial over an existing connection. #5455

Closed
elongl opened this issue Jun 22, 2022 · 2 comments
Closed

Dial over an existing connection. #5455

elongl opened this issue Jun 22, 2022 · 2 comments

Comments

@elongl
Copy link

elongl commented Jun 22, 2022

I want to have a setup in which machine A connects to machine B, but A is the gRPC server and B is the client.

My approach was to use a multiplexing library like yamux in order to first establish a regular TCP connection, and then to create a server stream on the client (machine A) and have the server (machine B) connect to it.

All of this would've been possible if gRPC had a way of dialing over an existing connection instead of necessarily receiving a target address. I wanted to know if there's a way to get this done, or altogether a different approach to solve this problem.

Thanks.

@easwars
Copy link
Contributor

easwars commented Jun 22, 2022

gRPC does not support initiating connections from the server to the client, and we have no plans of supporting this anytime in the near future.

@dfawley dfawley closed this as completed Jun 28, 2022
@noamApps
Copy link

noamApps commented Aug 3, 2022

@easwars hey there, this was possible up until (not including) v1.46, you could do something like

var existingConn net.Conn
// initialize existingConn...
grpcConn, err := grpc.DialContext(ctx, "", []grpc.DialOption{
    grpc.WithTransportCredentials(insecure.NewCredentials()),
    grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
        return existingConn, nil
    }),
}...,)

( notice the "" passed as target addr )

there several use cases for this technique and examples in the community, there is this old discussion in the repo about how to achieve this (#484 (comment))

I still could not pinpoint what broke my example in 1.46, I suspected it was related to #5274

Anyway, if you think I can still make the dial over reverse connection work in 1.46+ by changing the Dialer options it will be of great help

@elongl if you can use older grpc versions, 1.45 should work for your use case if I understood it correctly

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants