Skip to content

feat: WithGRPCDialOption for custom gRPC dial settings#23

Open
mlwelles wants to merge 2 commits into
matthewmcneely:mainfrom
mlwelles:feature/grpc-dial-options
Open

feat: WithGRPCDialOption for custom gRPC dial settings#23
mlwelles wants to merge 2 commits into
matthewmcneely:mainfrom
mlwelles:feature/grpc-dial-options

Conversation

@mlwelles

@mlwelles mlwelles commented Jun 4, 2026

Copy link
Copy Markdown

What this adds

WithGRPCDialOption(opt grpc.DialOption) — a general escape hatch for gRPC dial
settings the dedicated options do not cover: TLS transport credentials,
interceptors, keepalive parameters, and so on. Applied when opening a remote
(dgraph://) connection; ignored for embedded (file://) URIs.

client, err := mg.NewClient(
    "dgraph://localhost:9080",
    mg.WithGRPCDialOption(grpc.WithTransportCredentials(creds)),
    mg.WithGRPCDialOption(grpc.WithKeepaliveParams(kp)),
)

The problem it solves

The client exposed only a fixed set of gRPC knobs (e.g. WithMaxRecvMsgSize).
Anything else — mTLS, auth interceptors, custom keepalive — required forking the
connection code. WithGRPCDialOption lets callers pass any grpc.DialOption
straight through to the dial, so the client covers the long tail of gRPC
configuration without growing a dedicated option for each.

WithMaxRecvMsgSize is preserved and folded into the same dial-option assembly,
so the two compose rather than conflict.

Review round — changes since first push

Addresses the automated review (cubic):

  • Dedup cache key was lossy (P1): the client dedup key counted dial options
    (len(...)), so two clients to the same URI with one different option each
    produced the same key and were incorrectly merged. grpc.DialOption values
    are opaque and not comparable, so the key now includes each option's runtime
    identity. Differently configured clients are never merged; the cache errs
    toward keeping them apart.
  • Embedded consistency: dial options now contribute to the key only for
    remote (dgraph://) URIs, matching the documented "ignored for file://"
    behavior.
  • Weak test (P1): the cache-key test only checked 0-vs-1 option count. It
    now asserts that two clients with the same count but different options get
    different keys.

Tests

  • TestKeyDistinguishesGRPCDialOptions — different options at the same count
    yield different keys.
  • TestKeyIgnoresGRPCDialOptionsForEmbedded — dial options do not affect the
    key for file:// clients.
  • TestWithGRPCDialOptionAppends — options accumulate.

Documentation

A runnable ExampleWithGRPCDialOption showing TLS credentials and keepalive.

Adds WithGRPCDialOption(opt grpc.DialOption), a general escape hatch for
gRPC dial settings the dedicated options do not cover — TLS transport
credentials, interceptors, keepalive, and so on — on remote (dgraph://)
connections.

The existing WithMaxRecvMsgSize is folded into the same dial-option
assembly, so the two compose cleanly, and the client dedup key now counts
the custom dial options so differently-configured clients are not merged.
No change for embedded (file://) URIs.
@mlwelles mlwelles requested a review from matthewmcneely as a code owner June 4, 2026 20:06

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="dial_options_test.go">

<violation number="1" location="dial_options_test.go:27">
P1: TestKeyDistinguishesGRPCDialOptions only validates 0 vs 1 dial option count, not different values, masking a cache-key collision bug.</violation>
</file>

<file name="client.go">

<violation number="1" location="client.go:456">
P1: Cache key disambiguation for custom gRPC dial options is lossy (count-only), allowing collisions for different options and inconsistent behavior with documented embedded-mode ignore semantics.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread dial_options_test.go
Comment thread client.go Outdated
Addresses review feedback on WithGRPCDialOption:

- client.key() keyed custom gRPC dial options by count only, so two clients
  to the same URI with one different option each produced the same key and
  were merged in the dedup cache. The key now includes each option's runtime
  identity (grpc.DialOption is opaque and not comparable), so differently
  configured clients are never merged. The cache errs toward keeping clients
  apart rather than merging connections configured differently.
- Dial options apply only to remote (dgraph://) connections, so they now
  contribute to the key only for remote URIs — consistent with the documented
  "ignored for file://" behavior.

Tests:
- TestKeyDistinguishesGRPCDialOptions now also asserts two clients with the
  same option count but different options get different keys.
- TestKeyIgnoresGRPCDialOptionsForEmbedded asserts dial options do not affect
  the key for embedded (file://) clients.

Docs: add a runnable ExampleWithGRPCDialOption (TLS credentials + keepalive).
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.

1 participant