{"record":{"id":"8cd4a662a6f95047","repo":"micro/go-micro","slug":"deadline-exceeded","errorCode":null,"errorMessage":"deadline exceeded","messagePattern":"deadline exceeded","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"transport/nats/nats.go","lineNumber":186,"sourceCode":"\t}\n\n\t// no deadline\n\tif n.opts.Timeout == time.Duration(0) {\n\t\treturn n.conn.PublishRequest(n.addr, n.id, b)\n\t}\n\n\t// use the deadline\n\tch := make(chan error, 1)\n\n\tgo func() {\n\t\tch <- n.conn.PublishRequest(n.addr, n.id, b)\n\t}()\n\n\tselect {\n\tcase err := <-ch:\n\t\treturn err\n\tcase <-time.After(n.opts.Timeout):\n\t\treturn errors.New(\"deadline exceeded\")\n\t}\n}\n\nfunc (n *ntportClient) Recv(m *transport.Message) error {\n\ttimeout := time.Second * 10\n\tif n.opts.Timeout > time.Duration(0) {\n\t\ttimeout = n.opts.Timeout\n\t}\n\n\trsp, err := n.sub.NextMsg(timeout)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar mr transport.Message\n\tif err := n.opts.Codec.Unmarshal(rsp.Data, &mr); err != nil {\n\t\treturn err\n\t}","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/transport/nats/nats.go#L168-L204","documentation":"ntportClient.Send publishes to NATS and waits for completion (e.g. flush/ack) up to n.opts.Timeout; if the timer fires first it returns 'deadline exceeded'. This is a client-configured timeout on the send path, not a NATS server error.","triggerScenarios":"Send on a NATS connection that is slow, blocked, or disconnected so the pending operation doesn't complete within opts.Timeout (default when unset); long-blocking publishes during network partitions.","commonSituations":"Too-small Timeout option for large payloads or high-latency links; NATS broker unreachable/down so publishes hang until the deadline; closed NATS connection from an idle timeout.","solutions":["Increase the Timeout dial/client option to a value suited to your payload size and network latency","Check NATS server health and client connectivity (reconnect logic, servers list) so sends complete quickly","Add retry-with-backoff around Send on this error; consider a longer default or context-aware send for critical messages"],"exampleFix":"// before\nnats.NewTransport(transport.Timeout(time.Millisecond * 100))\nclient.Send(m) // deadline exceeded on slow links\n// after\nnats.NewTransport(transport.Timeout(time.Second * 5))\nif err := client.Send(m); err != nil {\n\t// retry with backoff\n\ttime.Sleep(time.Second)\n\terr = client.Send(m)\n}","handlingStrategy":"retry","validationCode":"if timeout < time.Second {\n\treturn errors.New(\"nats timeout too low for Send\")\n}","typeGuard":null,"tryCatchPattern":"var err error\nfor i := 0; i < 3; i++ {\n\tif err = client.Send(m); err == nil || err.Error() != \"deadline exceeded\" { break }\n\ttime.Sleep(time.Duration(1<<i) * 100 * time.Millisecond)\n}","preventionTips":["Configure a realistic Timeout for payload size and network latency","Enable NATS reconnect with multiple server addresses","Monitor broker connectivity; alert before sends start timing out"],"tags":["transport","nats","timeout","network"],"backgroundTag":"send-timeout","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}