pytogo / portforward

Kubernetes Port-Forward Go-Edition For Python

Home Page:https://portforward.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling Incomplete Closure of upstream_conn in Port Forwarding

webfolderio opened this issue · comments

  • portforward version: 0.6.0
  • Python version: 3.11
  • Operating System: Linux

Description

The current implementation of the port forwarding functionality in the Rust code has an issue where closing the TCP listener via take_until(rx) does not ensure that the upstream_conn (the connection to the pod) is also closed. This results in a scenario where, even after client_conn (the client's connection) is terminated using the stop function, upstream_conn remains open. The copy_bidirectional function, designed to operate until both streams are closed, continues running if one stream is active, leading to potential indefinite waiting. Additionally, the forwarder's abort method isn't triggered in this process, exacerbating the problem. A solution is needed to guarantee that when client_conn is stopped, both upstream_conn and the forwarder are also properly terminated, avoiding any persistent, unneeded connections.

As an improvement, integrating the forwarder's abort method into the stop function could effectively address the incomplete closure issue.

Thx @webfolderio for the detailed issue. At the moment I have nearly zero spare time. :-/ But I hope that I can start working soon on this. (or maybe someelse want to pick this up.)

@webfolderio The tokio docs mentions that the other stream should be shut down. Isnt this enough? I added a log that should only appear when the future of copy_bidirectional finishes.

The future will complete successfully once both directions of communication has been shut down.

And in my test the debug message appears. 🤔

I will close the issue for now. Feel free to re-open it when new details are available.