Preserve independent background sessions through owner shutdown and idle cleanup

This commit is contained in:
2026-11-07 16:23:20 +00:00
parent 4ead2abdbf
commit b15597662f
9 changed files with 360 additions and 51 deletions
+4 -3
View File
@@ -55,8 +55,9 @@ type bridge struct {
detached time.Time
}
// Options describes one private, database-scoped bridge. MaxDetached bounds its
// lifetime without a Pipelines client, even with an unresolved approval.
// Options describes one private, database-scoped bridge. Positive timeout
// values opt into detached expiry; zero keeps the original upstream connection
// and its live sessions/callbacks until explicitly stopped.
type Options struct {
Dir, Upstream string
Idle, MaxDetached time.Duration
@@ -221,7 +222,7 @@ func (h *bridge) expire(idle, maxDetached time.Duration) {
return
case <-ticker.C:
h.mu.Lock()
expired := h.active == nil && (time.Since(h.detached) >= maxDetached || (len(h.pending) == 0 && time.Since(h.detached) >= idle))
expired := h.active == nil && ((maxDetached > 0 && time.Since(h.detached) >= maxDetached) || (idle > 0 && len(h.pending) == 0 && time.Since(h.detached) >= idle))
h.mu.Unlock()
if expired {
h.cancel()