Skip to content

GRPC: best way to connect to unix sockets - possible regression? #1846

Closed
@tux21b

Description

@tux21b

Previously, i used following code to support TCP and Unix sockets:

// SchemaDialer supports an optional protocol prefix
// (like "tcp://" or "unix://"). TCP is the default.
func SchemaDialer(addr string, timeout time.Duration) (net.Conn, error) {
	proto, addr := SplitSchemaAddr(addr)
	return net.DialTimeout(proto, addr, timeout)
}

// SplitSchemaAddr parses an address with an optional protocol prefix
// (like "tcp://" or "unix://"). TCP is the default.
func SplitSchemaAddr(addr string) (string, string) {
	parts := reSchema.FindStringSubmatch(addr)
	proto, addr := parts[1], parts[2]
	if proto == "" {
		proto = "tcp"
	}
	return proto, addr
}

var reSchema = regexp.MustCompile("^(?:([a-z0-9]+)://)?(.*)$")

The usage itself looked like grpc.Dial(addr, grpc.WithDialer(SchemaDialer)) and worked fine with previous GRPC versions. The value of addr is for example unix:///run/example.sock and the old GRPC behavior was that the value of addr gets passed to the dialer unmodified.

After a recent update to 1.9.2 the behavior has changed significantly. The address gets parsed before, the schema and the first slash gets removed and "run/example.sock" (note the relative path and missing schema) is passed to my SchemaDialer(). This all happens in the line cc.parsedTarget = parseTarget(cc.target) within grpc.DialContext() and is not configureable.

Without access to the original address, the addr parameter for the dialer is completely useless to me. I can probably ignore it and use a value from a closure, but I guess that's not the intended way.

Any help is appreciated! Many thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions