Question about IIS /API Issue
Had a really weird issue at work today in production where a specific endpoint on an api stopped working and would return 500 just saying 'An Error Has Occured' (or something like that).
From the checks I did this 1 endpoint had just stopped working while all other endpoints in the project (and even endpoints in the same controller) continued to work. We had no code or database changes deployed to production around this time (or even for the previous week). It also seemed like the error wasn't even getting to the bit where it actually runs the endpoint logic etc, almost like it was at the IIS level or network level or something. I say this because one thing we noticed is that it would return a 500 response even if you called the endpoint unauthenticated (but if it actually hit our code it would have returned unauthorized)
In the end restarting the app pool the api was in from IIS fixed the issue. Any ideas?
42 Replies
Did you have another service, coming to the controller by DI, which crashed? How is the scope of the controller and the corresponding service? Maybe you have initialized the underlying service as singleton, while controllers in normal cases are registered in scoped way. So the other endpoints just worked fine because of the new scope and so on.
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Thanks for the response 🙂 I believe everything is registered scoped in this project and the actual code is very simple controller layer -> buisness logic layer -> data access layer using entity framework. The first endpoint returns all records from the database (this one wasnt working) while the endpoint that returns records by id was working and both endpoints have the same depedencies so I don't think it was a singleton issue but I will check the code at work tomorrow!
Apologies for cross post, haven't been to this disc in a while and forgot about the questions section. I couldn't see anything in the event viewer that would indicate a problem but I will check again. We have IIS logs which show requests but they are not very detailed just showing which endpoint was called, statuscode etc
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Also worth mentoning this is a slightly older .net framework project but it does use dependency injection
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
and the endpoint in question has been working fine for basically multiple years with no changes
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Not really, we don't have great logging system, mostly try/catch in controller endpoints that log to database but there was nothing in the database
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Yeah it definitely needs some work, but my thinking is that this error was happening outside of the code I had written, as if IIS was automatically returning a 500 or something on this specific endpoint
TeBeCo
webform ? owin ? system.web ? aspnetcore 2.1 /
Quoted by
<@689473681302224947> from #Question about IIS /API Issue (click here)
React with ❌ to remove this embed.
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
It returned Internal Server Error and JSON { "Message": "An error has occurred." }
I checked with postman and I think it return same via browser but didn't check exact status code
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
In that case it must be something "before" my controller endpoint was hit, because that code all has databse logging, would return a proper errror message etc. Before it hits that endpoint there is also an Auhorize attribute and it clearly didnt hit that either
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
*Authorize
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
TeBeCo
webform ? owin ? system.web ? aspnetcore 2.1 ?
Quoted by
<@689473681302224947> from #Question about IIS /API Issue (click here)
React with ❌ to remove this embed.
It's a .net framework 4.6.x project I think
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
2min ill see if I can find it
I can see references to system.web.http etc but no owin
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
No startup but yes to global.asax and that has reference to system.web.http and controllers inherit from ApiController
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
No middlewares no
and no owin references but there is system.web reference
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
We have a filter that is used for auth before that actual endpoint method is called but I am certain that wasnt even being hit from sending the unauth'd requests so for sure the error is being returned before that point
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
I checked and all dependencies are scoped for the request no singletons
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Actually maybe not, we are using Unity for DI and PerResolveLifetimeManager so maybe it isn't scoped per request.....
I don't fully understand how that works
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
But there is no unique dependency here that would fail and cause one of the endpoints to work and one wouldn't, they all share the same ones so I think that most likely isn't the problem
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Yeah no worries, thankyou for your suggestions I really appreciate it!
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Maybe 100 endpoints and is a dependency for many other systems
But it is not complex, mostly just getting data from a database and returning it
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Yeah it's a big and old system that needs replacing for sure 😂
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View