Skip to content

MeshSync exec: synchronize channelPool access and fix subscription/goroutine teardown #585

Description

@leecalcote

Two related, pre-existing concurrency/lifecycle issues in the exec session code (meshsync/exec.go, meshsync/handlers.go), surfaced by review on #573. Deferred from that PR because a correct fix is a broader refactor that risks the exec request/reply protocol, which #573 was scoped to preserve.

1. h.channelPool is a plain map shared across goroutines

channelPool holds both fixed system channels (Stop/ReSync/OS, set once at init) and dynamic per-session exec channels. Exec goroutines mutate it (h.channelPool[id] = ...; delete(h.channelPool, id) in streamSession/terminate; execCleanup) while other goroutines read or range it (getActiveChannels ranges the whole map; <-h.channelPool[channels.Stop] in select loops across handlers.go/exec.go). Concurrent map read+write can panic at runtime.

Fix direction: move the mutable exec-session channels into their own sync.Mutex-guarded map so the system channelPool is read-only after init; or add a Handler-wide lock and read system-channel refs into locals before selecting on them. Also fix getActiveChannels, which currently ranges the whole pool and returns system-channel keys as "active sessions".

2. Exec input subscription and its drain goroutine can't be torn down cleanly

streamSession subscribes to input.<id> via SubscribeWithChannel and, on session end, parks a drain goroutine (<-done; for range subCh {}) that never exits because subCh is never closed. Root cause: MeshKit's broker.Handler interface has no Unsubscribe. Once MeshKit exposes it, streamSession should unsubscribe on teardown and drop the drain goroutine.

Depends on: MeshKit broker.Handler.Unsubscribe (designed in #580).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions