Skip to content

Track and clean up detached port-forward processes across envrc and eval workflows #330

Open

Description

@coderabbitai

Summary

Make detached port-forward lifecycle handling consistent across --envrc and --eval workflows.

Requested by @mclasmeier during review of PR #329.

Verified behavior

At PR #329's base revision (257fffb9faff7e349280e8a3d960a1dc39968538), the deployer reads ROXIE_PORT_FORWARD_PID, retains the PID returned by StartDetached, exports it to the envrc file, and uses it during teardown.

However, configureCentralEndpoint starts a new detached forwarder and overwrites the previously tracked PID without stopping the previous process. This replacement-cleanup gap predates PR #329.

PR #329 adds a separate gap in roxie shell --eval: it discards the PID returned by StartDetached, and printExports does not export ROXIE_PORT_FORWARD_PID. The current shell can therefore retain a stale PID or have no PID for the new forwarder.

Required changes

  • Retain and export the PID of the detached forwarder created by roxie shell --eval.
  • Define consistent replacement handling for an existing tracked forwarder in both workflows.
  • After the replacement forwarder is ready, stop the previously tracked forwarder before replacing its tracked PID.
  • Preserve the existing forwarder and its tracking if replacement startup fails.
  • Ensure teardown can stop the currently tracked detached forwarder.
  • Handle absent, invalid, or already-exited tracked PIDs without failing the workflow. Account for stale PID safety.

Affected areas

  • cmd/shell.go: detached startup in eval mode.
  • cmd/subshell.go: environment exports.
  • internal/deployer/deploy_via_operator.go: detached startup and PID replacement.
  • internal/deployer/deployer.go: PID import, envrc export, and teardown.
  • internal/portforward/portforward.go: detached process lifecycle.
  • tests/e2e/basic_test.go: existing envrc port-forward coverage.

Acceptance criteria

  • Both envrc and eval output identify the newly created detached forwarder with ROXIE_PORT_FORWARD_PID.
  • Repeated setup with a previously tracked forwarder does not leave that forwarder untracked and running after successful replacement.
  • Failed replacement does not stop the previous working forwarder.
  • Teardown stops the currently tracked forwarder.
  • Regression coverage includes PID export, successful replacement, failed replacement, and stale or missing PID handling.

References

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

Metadata

Metadata

Assignees

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