[BUG] v1 API proxy leaks gRPC CallbackSerializer goroutines (per-request client never closed)
Describe the issue
We run hatchet-lite self-hosted and noticed go_goroutines climbing steadily in production with no plateau, which traced back to the v1 API proxy. Filing per CONTRIBUTING before opening a PR.
The proxy opens a new gRPC client per proxied request and never closes it, leaking the connection's resolver/balancer CallbackSerializer goroutines without bound.
api/v1/server/handlers/v1/proxy/proxy.go → Proxy.Do calls InternalClientFactory.NewGRPCClient(...) on every request and drops the result. GRPCClient (pkg/client/v1/grpc-client.go) can't be closed anyway: it has no Close() and doesn't retain the *grpc.ClientConn (it only keeps the admin stub). So each proxied request creates a grpc.NewClient ClientConn that becomes unreachable and leaks its grpcsync.CallbackSerializer goroutines.
This is the same leak class noted (and left open) in #170, now traced to a concrete request path.
Environment
- Engine: Self-hosted
hatchet-litev0.88.6 (code is identical onmainas of 2026-06-25) - grpc-go: v1.80.0
Expected behavior
A long-running engine under steady dashboard/API traffic should not accumulate goroutines. Per-request gRPC clients should be closed after use.
Code to Reproduce, Logs, or Screenshots
Repro: drive repeated proxied requests, e.g. POST /api/v1/stable/tenants/{id}/workflow-runs/trigger with a non-existent workflow (still reaches Proxy.Do before the RPC fails), and watch go_goroutines:
- ~30 requests → +~300 goroutines, never reclaimed.
In production, go_goroutines grew linearly ~1,100/hour with no plateau, reaching 300k+ over ~2 weeks on a single pod (RSS ~1.5 GiB), recoverable only by restarting the process. A SIGQUIT goroutine dump showed 20,433 of 21,840 goroutines (93.6%) parked in grpcsync.(*CallbackSerializer).run ([chan receive]), created by NewCallbackSerializer, with no hatchet driver goroutine still on the stack (the creators had already returned).
Additional context
Minimal fix: retain the conn on GRPCClient, add Close(), and defer c.Close() in Proxy.Do. All proxied methods are unary, so the connection is closed only after the response is fully returned — no use-after-close.
How this was verified: I applied the fix on a fork, built hatchet-lite from it (the official v0.88.6 image with only the rebuilt binary overlaid), deployed it to a dev cluster, and ran an A/B by driving the identical proxied requests above (reaching Proxy.Do was confirmed by the HTTP 400 "workflow not found" response):
- unpatched: 30 requests → +300 goroutines, never reclaimed
- patched: 30 requests → +1
- patched, after 120 requests: a
SIGQUITdump showed 0grpcsync.CallbackSerializergoroutines — identical to baseline (the unpatched build would show ~1,200)
So the per-request connections are reclaimed: the leak is eliminated, not just slowed.
AI Disclosure
I acknowledge that an LLM was used in the creation of this Issue, in accordance with Hatchet's AI_POLICY.md.
Details: This was done primarily with Claude Code (Opus) — it ran the production goroutine dump, traced the root cause, wrote the patch, built the patched engine, and ran the dev A/B verification. I directed the investigation, reviewed all findings, and edited this report before submitting.
Source: hatchet-dev/hatchet