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

Fix Streaming Issues & Cleanup Async #493

Merged
merged 5 commits into from
Aug 2, 2023
Merged

Conversation

squidarth
Copy link
Collaborator

@squidarth squidarth commented Aug 1, 2023

Summary

I noticed a couple issues while working through the Streaming stuff.

  1. There is an issue with how we were handling semaphore management. We were offloading the user's predict work to a background task, and releasing the semaphore before that finishes. This means that users might be getting more concurrency than they ask for.

  2. If a stream throws an error partway through, right now, the user does not see a good error in the logs, and the client hangs for a minute.

In addition, in this PR, did some cleanup on the async stuff.

Solutions

  • Wrote a semaphore manager so we can defer release until the user's generator has been fully read from
  • Catch errors and log them when there's an error, and ensure that we yield a None, so that the response generator can terminate, and doesn't hang for 60 seconds.
  • We don't need to attach a thread pool executor to asyncio anymore, since we are using the anyio workers now instead.

Testing

Added integration tests for both of these complicated cases, and will test manually as well on dev.

Copy link
Collaborator

@bolasim bolasim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! thank you

await queue.put(ResponseChunk(chunk))
except Exception as e:
self._logger.exception("Exception while reading stream response: " + str(e))
finally:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat trick!

@squidarth squidarth merged commit c93c9ac into main Aug 2, 2023
@squidarth squidarth deleted the sshanker/async-cleanup branch August 2, 2023 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants