Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 3, 2025

PortForwardResult's underlying WebSocketStreamHandler remains open unless closed remotely, and methods like getInputStream() throw IllegalStateException when closed with no way to check state first.

Changes

  • WebSocketStreamHandler: Add isClosed() method to expose closed state
  • PortForwardResult: Implement Closeable, add isClosed() and close() methods

Aligns with existing Attach.AttachResult which already implements Closeable.

Usage

try (PortForwardResult result = forward.forward(pod, ports)) {
    if (!result.isClosed()) {
        InputStream is = result.getInputStream(8080);
        // ...
    }
}

Fixes #2911

Original prompt

This section details on the original issue you should resolve

<issue_title>PortForwardResult does not expose methods to close WebSocketStreamHandler nor expose is state</issue_title>
<issue_description>Describe the bug
PortForwardResult's underlying WebSocketStreamHandler will remain open unless the WebSocket is closed remotely. Furthermore, PortForwardResult's methods that return streams will throw an IllegalStateException if the handler is closed, but does not expose a way to check the handler state to avoid the exception.

This is related to #865 but more specific.

Client Version
16.0.0

Kubernetes Version
1.24.0

Java Version
Java 11

To Reproduce
Steps to reproduce the behavior:

  1. Call PortForward.forward
  2. Call getInputStream/getOutputStream on the result with try-with-resources pattern

Expected behavior

  1. There is a way to check the state to avoid an IllegalStateExeption, e.g. exposing WebSocketStreamHandler.state via PortForwardResult.
  2. There is a way to close the underlying WebSocketStreamHandle, e.g. having PortForwardResult implement AutoCloseable and closing the WebSocketStreamHandle on close.

Server (please complete the following information):

  • OS: Linux (Debian Bookworm)
  • Environment: KinD
  • Cloud: None
    </issue_description>

Comments on the Issue (you are @copilot in this section)

@brendandburns We'd be happy to have a PR to extend support to cover this. @ /assign I don't know much about java, but i know C. I would like to give it a try. new to open source. Will try my best. @ @brendandburns I don't know much right now. How much time do I have to resolve this Issue? Asked this to get an idea about how much time i have to learn.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 3, 2025
- Add isClosed() method to WebSocketStreamHandler to expose the closed state
- Make PortForwardResult implement Closeable interface
- Add isClosed() method to PortForwardResult to check handler state
- Add close() method to PortForwardResult to close the underlying handler
- Add tests for the new functionality

Fixes #2911

Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 3, 2025
Copilot AI changed the title [WIP] Expose methods to check WebSocketStreamHandler state Make PortForwardResult implement Closeable and expose handler state Dec 3, 2025
Copilot AI requested a review from brendandburns December 3, 2025 02:16
Copilot finished work on behalf of brendandburns December 3, 2025 02:16
@brendandburns
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 3, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, Copilot

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@brendandburns brendandburns marked this pull request as ready for review December 4, 2025 04:24
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 4, 2025
@k8s-ci-robot k8s-ci-robot merged commit e88269c into master Dec 4, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PortForwardResult does not expose methods to close WebSocketStreamHandler nor expose is state

3 participants