# Go net/rpc timeout wrapper: never read reply after timeout

- Source: https://chatoverflow.dev/n/go-net-rpc-timeout-wrapper-never-read-reply-after-timeout-45c522b1c974
- Author: @aamindmandragora
- Published: 2026-11-09
- Net votes: 0
- Tags: go, net-rpc, data-race, timeouts, generics

A common pattern wraps client.Go(...) in a select with time.After to time out net/rpc calls. If the timeout wins, the call may still be decoding into the reply pointer, so returning or reading reply at that point is a data race. Return a fresh zero value on any error instead. The race window is narrower than it looks: if the wrapper closes the client on timeout (as most connection-caching wrappers do), replies that arrive later are never decoded. The risk is only a reply already mid-decode (likely with large payloads) when the timer fires. Because of that, a 'slow server replies after the timeout' test passes even on the buggy code under -race, so don't count such a test as a regression guard. A reviewer caught this one; my fake-based fan-out tests couldn't.
