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

Proposal: Remove send and receive timeouts #1387

Closed

Conversation

ueman
Copy link
Contributor

@ueman ueman commented Jan 17, 2022

This PR removes send and receive timeouts. It's meant as a basis for a discussion.

As you can see, the current implementation just adds send and receive timeouts itself. It's not a concept of the underlying APIs (xhr and HttpClient). The Http2 adapter doesn't support it at all.

Removing these timeouts could lead to a pretty nice amount of reduced complexity and code.

@kuhnroyal
Copy link
Member

I agree with this, what do you think @wendux?

@jgoyvaerts
Copy link
Contributor

I don't think this is a good idea, a lot of users of dio depend on this implementation and would have to reimplement this themselves. We can make them optional and improve them if they work incorrectly, but removing them seems like a bad idea

@ueman
Copy link
Contributor Author

ueman commented Jan 20, 2022

I don't think this is a good idea, a lot of users of dio depend on this implementation and would have to reimplement this themselves.

Do you have any data on that?

Also since you're against this, I'd really like to hear some use cases for these two timeouts.

@jgoyvaerts
Copy link
Contributor

I don't think this is a good idea, a lot of users of dio depend on this implementation and would have to reimplement this themselves.

Do you have any data on that?

Also since you're against this, I'd really like to hear some use cases for these two timeouts.

I don't have any data on that, since it would be hard/impossible to get that data.

I assume (this is my main use case anyway) people use dio to consume their backend API in their app, so they only have to configure stuff once like auth tokens, custom headers on each request, etc.

Removing these timeouts would mean you either fall back to the OS default timeout (which can vary per platform, and can be longer than you want), or means users of this library have to implement their own wrapper if they want their requests to timeout after X seconds.

@ueman
Copy link
Contributor Author

ueman commented Jan 22, 2022

Removing these timeouts would mean you either fall back to the OS default timeout (which can vary per platform, and can be longer than you want), or means users of this library have to implement their own wrapper if they want their requests to timeout after X seconds.

The connectionTimeout does not get removed, only the send and receive timeouts gets removed if this code is merged.

@jgoyvaerts
Copy link
Contributor

My bad, misunderstood then.

Still seems weird to remove the feature rather than fixing/implementing it properly. Once it's removed, a user of the library would have no way of implementing this himself because it can only be implemented on request level, which Dio is hiding, correct?

@kuhnroyal
Copy link
Member

Well, the concept of receive/send timeout don't technically exist in the underlying clients.
They just start a timer and throw an error once the timer completes. The request doesn't get canceled and may still run and successfully complete but you wouldn't know.

Would really love to hear @wendux thoughts. What was the motivation for adding this?

@amondnet
Copy link
Contributor

amondnet commented Mar 4, 2022

Doesn't abort cancel the request?

I think once we have a response, instead of request.abort() we need to use response.detachSocket().

https://pub.dev/documentation/http/latest/io_client/IOStreamedResponse/detachSocket.html

There is a PR that support for request timeout.
dart-lang/http#521

I think this is worth doing because timeouts are a common case for wanting to abort requests, and they are easier to get wrong than to get right. The naive approach of .timeout doesn't clean up resources and the entire result is still going to get read. Even with a general mechanism to abort requests a timeout argument is handy because we can handle the timer cancellation which would otherwise be boilerplate. We also likely can't arrive at a solid design for request aborting in general, but the API design with timeout: argument is fairly straightforward.

@ueman
Copy link
Contributor Author

ueman commented Mar 4, 2022

Doesn't abort cancel the request?

I believe DIO doesn't yet make use of it.

),
StackTrace.current,
);
xhr.abort();
Copy link
Contributor

Choose a reason for hiding this comment

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

@ueman abort is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, thanks for clarifying 👍

@wendux
Copy link
Contributor

wendux commented Mar 30, 2022

Thanks this PR, but I prefer to agree with @amondnet "timeouts are a common case for wanting to abort requests".

@ueman
Copy link
Contributor Author

ueman commented May 9, 2022

Thanks for your feedback. I'm closing this as there seems to be some use case for this.

@ueman ueman closed this May 9, 2022
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.

None yet

5 participants