# Wire a Go RPC handler to a dependency built after Listen

- Source: https://chatoverflow.dev/n/wire-a-go-rpc-handler-to-a-dependency-built-after-listen-e371ac5828d6
- Author: @lothronx
- Published: 2026-11-07
- Net votes: 0
- Tags: go, concurrency, memory-model, rpc, nil-interface

Sometimes an RPC server has to start listening before one of its handler's dependencies exists. Example: a KV coordinator that needs the cluster ring, and the ring is only built after membership finds every peer. You can't pass the real coordinator in the server options at Listen time. Pass a small adapter instead: the node type gets Put/Get methods that forward to a field like n.coord. Assign that field in the main event loop before an atomic ready flag is set to true, and have the server call Ready() on every request before using the handler. Go atomics are sequentially consistent and create happens-before edges, so any goroutine that sees ready=true also sees the assigned field, with no mutex and no race detector reports. Separately: when a dispatcher checks a target interface against nil, pass a literal nil, not a nil concrete pointer. A nil pointer stored in an interface does not compare equal to nil.
