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

"Expected coroutine function, got method" error when portforwarding #566

Closed
dhorkel opened this issue Jan 27, 2025 · 5 comments · Fixed by #567
Closed

"Expected coroutine function, got method" error when portforwarding #566

dhorkel opened this issue Jan 27, 2025 · 5 comments · Fixed by #567
Labels
bug Something isn't working sync/async Related to sync/async support

Comments

@dhorkel
Copy link

dhorkel commented Jan 27, 2025

Which project are you reporting a bug for?

kr8s

What happened?

When using a jumpbox to forward ports (ultimately for connecting to a database) and error is raised.

from kr8s.objects import Service

service = Service.get("my-service", namespace="my-namespace)
portforward = service.portforward(45667, 45667)

Results in the error:

Exception in thread Thread-1 (run_forever):
Traceback (most recent call last):
  File "C:\Python312\Lib\threading.py", line 1073, in _bootstrap_inner
>>>     self.run()
  File "C:\Python312\Lib\threading.py", line 1010, in run

    self._target(*self._args, **self._kwargs)
  Fi    return run_sync(self.run_forever)()  # type: ignore\.venv\Lib\site-packages\kr8s\portforward.py", line 31, in run_forever
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dhorkel\code\source\repos\encord_interface\.venv\Lib\site-packages\kr8s\_async_utils.py", line 123, in run_sync
    raise TypeError(f"Expected coroutine function, got {coro.__class__.__name__}")

Anything else?

I have confirmed this error does not occur in 0.19.1 and does occur in both 0.20.2 and 0.20.1. I am using Python 3.12.2 and using a Windows machine.

@dhorkel dhorkel added the bug Something isn't working label Jan 27, 2025
@jacobtomlinson jacobtomlinson added the sync/async Related to sync/async support label Jan 27, 2025
@jacobtomlinson
Copy link
Member

This is almost certainly related to the changes in #551

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Jan 27, 2025

I'm guessing you're calling also portforward.run_forever() which you didn't include in your example. I found some bad sync wrapping in that method that was introduced in #551, should be fixed in #567.

Run forever is a little tricky to test because it does just that, it blocks forever.

@jacobtomlinson
Copy link
Member

Just pushed a v0.20.3 tag with this fix.

@dhorkel
Copy link
Author

dhorkel commented Jan 27, 2025

I'm guessing you're calling also portforward.run_forever() which you didn't include in your example. I found some bad sync wrapping in that method that was introduced in #551, should be fixed in #567.

Run forever is a little tricky to test because it does just that, it blocks forever.

I'm actually just running portforward.start() after but saw the error raised before it got there.

Thank you for the quick fix! I'll test it as soon as it goes through.

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Jan 28, 2025

Ah yeah, start() just calls run_forever() in a background thread, so the fix should still be right.

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

Successfully merging a pull request may close this issue.

2 participants