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

Don't throw IllegalStateException when no instances are available #478

Open
OrangeDog opened this issue Feb 24, 2017 · 11 comments
Open

Don't throw IllegalStateException when no instances are available #478

OrangeDog opened this issue Feb 24, 2017 · 11 comments

Comments

@OrangeDog
Copy link

Once it comes out of a RestTemplate it should be a RestClientException, preferably a ResourceAccessException, so it can be handled consistently.

At the moment it is annoying to deal with.

@spencergibb
Copy link
Member

Not sure I agree. From RestClientException

"Base class for exceptions thrown by {@link RestTemplate} whenever it encounters client-side HTTP errors."

I definitely wouldn't use ResourceAccessException

Exception thrown when an I/O error occurs

Neither one of those things happens when no instances are available.

How often do you deal with no instances available?

@OrangeDog
Copy link
Author

OrangeDog commented Feb 24, 2017

No instances being available is a client-side HTTP error. If you chose one you thought was available but it turned out not to be, a ResourceAccessException would be thrown. Pre-knowledge of this shouldn't throw a generic, unexpected exception.

How often do you deal with no instances available?

That's not really relevant. When it does happen I need to be able to deal with it appropriately, which already happens for non-load-balanced RestTemplates.

@spencergibb
Copy link
Member

I can be convinced of RestClientException, but I don't think ResourceAccessException is appropriate.

@ryanjbaxter
Copy link
Contributor

The key term is "HTTP errors". Not having any instances available doesnt seem like an HTTP error to me.

@OrangeDog
Copy link
Author

@ryanjbaxter have you looked at how Spring already uses it?
As I said, you already get RestClientException if no instances are available - it's only in this specific case when Spring Cloud is involved that it's changed into an IllegalStateException.

@ryanjbaxter
Copy link
Contributor

Sorry I was consumed by the terminology "instances". When using a plain RestTemplate (without it being load balanced) I wouldnt think that would apply.

@OrangeDog
Copy link
Author

OrangeDog commented Feb 27, 2017

Well in a plain RestTemplate if the only instance is down then you get RestClientException.
In a @LoadBalanced RestTemplate if all the instances are down but not currently marked, you get RestClientException.
If anything else goes wrong during any kind of RestTemplate execution, you get RestClientException.

In this one specific case you get IllegalStateException when it's clearly not even an illegal state: it can happen as a matter of course.

@spencergibb
Copy link
Member

In the 1st case, you are actually trying to create a connection (there's no notion of instances). In the 2nd it never gets to that point. We've marked it for team discussion. The arguing of semantics here isn't helping.

@OrangeDog
Copy link
Author

I'm not arguing semantics, I'm pointing out practical reasons why this should be changed.

@rkettelerij
Copy link

Has this been discussed yet within the spring-cloud team? I also believe a more specialised runtime exception would be appropriate here. ISE is too general for this case.

@spencergibb spencergibb transferred this issue from spring-cloud/spring-cloud-netflix Feb 7, 2019
@spencergibb
Copy link
Member

There are two steps a new exception and catching and exception in the LoadBalancerInterceptor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants