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

When ctx is canceled, StreamPrediction will throw an error #42

Open
yan5xu opened this issue Feb 20, 2024 · 3 comments
Open

When ctx is canceled, StreamPrediction will throw an error #42

yan5xu opened this issue Feb 20, 2024 · 3 comments

Comments

@yan5xu
Copy link

yan5xu commented Feb 20, 2024

If the ctx used by StreamPrediction is canceled, StreamPrediction will throw an error.
The expectation is that StreamPrediction stops processing without throwing an error.

@mattt
Copy link
Member

mattt commented Feb 20, 2024

Hi @yan5xu. Thanks for reporting this. It was our intention for context cancellation to return without an error. Can you share what error is being produced?

@yan5xu
Copy link
Author

yan5xu commented Feb 21, 2024

Hi @yan5xu. Thanks for reporting this. It was our intention for context cancellation to return without an error. Can you share what error is being produced?

lol, below is the error msg I collected in the log

failed to send request: Get "https://streaming-api.svc.us.c.replicate.net/v1/streams/fge5z76wnqszkj5rqi3cxr4w6bwirlju6vxfvqxeoaiqnrij7sga\": context canceled

@mattt
Copy link
Member

mattt commented Mar 11, 2024

@yan5xu Thank you for clarifying. If the error happens because the context is canceled for the original HTTP request for the stream, I think it's reasonable to bubble that up. And on reflection, I think it's less confusing if context errors are always returned, even when used to cancel a stream. Would you agree with that?

In the meantime, my recommendation would be to check for context cancellation errors and handle those differently:

if errors.Is(err, context.Canceled) {
    // ...
}

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

No branches or pull requests

2 participants