Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync port forward context managed hangs on exit for around a minute #570

Open
jacobtomlinson opened this issue Feb 3, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@jacobtomlinson
Copy link
Member

Which project are you reporting a bug for?

kr8s

What happened?

While investigating #569 I noticed a hang locally when running a sync port forward context manager. It seems to take a long time to exit the context manager.

# Create web server Pod
kubectl run webserver --image nginx --port 80
kubectl expose po webserver
import kr8s
import requests
import time

[svc] = kr8s.get("svc", "webserver")
start = time.time()
with svc.portforward(remote_port=80, local_port="auto") as local_port:
    print(f"After enter: {time.time() - start:.1}s")
    resp = requests.get(f"http://localhost:{local_port}/")
    print(f"After rerquest: {time.time() - start:.1}s")
print(f"After exit: {time.time() - start:.1}s")
After enter: 0.001s
After rerquest: 0.04s
After exit: 70s
# Clean up
kubectl delete svc/webserver po/webserver

Anything else?

No response

@jacobtomlinson jacobtomlinson added the bug Something isn't working label Feb 3, 2025
@jacobtomlinson
Copy link
Member Author

This does not happen in the asyncio implementation.

In [2]: import kr8s
   ...: import httpx
   ...: import time
   ...: 
   ...: [svc] = [s async for s in kr8s.asyncio.get("svc", "webserver")]
   ...: start = time.time()
   ...: async with svc.portforward(remote_port=80, local_port="auto") as local_port, httpx.AsyncClient() as client:
   ...:     print(f"After enter: {time.time() - start:.1}s")
   ...:     resp = await client.get(f"http://localhost:{local_port}/")
   ...:     print(f"After rerquest: {time.time() - start:.1}s")
   ...: print(f"After exit: {time.time() - start:.1}s")
After enter: 0.01s
After rerquest: 0.05s
After exit: 0.05s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant