The remote server returned an error: (502) Bad Gateway

ukerandi
ukerandi used Ask the Experts™
on
Hi Experts,
I'm getting following  error message.
But this will get after nearly 19000 records downloaded.
earlier it's 401-unauthorized.but after reconnect it's worked until 19,000 records.
after that following error generated any idea?
i'm using RestSharp

The remote server returned an error: (502) Bad Gateway


I have found kind of solution but i don't know how to use  use with  Restsharp
see someone put solution for this but not Restsharp

https://stackoverflow.com/questions/2159361/error-502-bad-gateway-when-sending-a-request-with-httpwebrequest-over-ssl

https://stackoverflow.com/questions/10205854/error-the-remote-server-returned-an-error-401-unauthorized

Any idea much appricicated. main problem this will take time to long time to download after one hour error generate.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
This usually means there's some pipeline failure.

In other words... Varnish talks to NGINX, then NGINX talks to IIS or Apache.

And one of these connections is overwhelmed with data, then dies.

To debug this, refer to all server side logs looking for exact layer of software that died.

You'll then either retune this layer of code or just remove the layer, as every layer of code injected into a pipeline creates additional security + performance + debugging + maintenance problems.

Author

Commented:
@David Favor
Thank you very much for reply
so server side i can't do anything.I'm downloading data from different service provider.
so no access forthere server.
so ony i can do with my code. do you have any example for code.
at the moment my using RESTSHARP
also i'm not undertsand this with code
You'll then either retune this layer of code or just remove the layer
Eduard GherguArchitect - Coder - Mentor

Commented:
Hi,
There is any possibility to get a timeout on the database query?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Author

Commented:
@Eduard Ghergu
Thank you very much for your reply
Please find added screenshot. this is the what you asking.if not can youlet me know how to increase
the timeout on the database query
timeout.png
David FavorFractional CTO
Distinguished Expert 2018

Commented:
You said, "so server side i can't do anything.I'm downloading data from different service provider."

This will require you to open a trouble ticket with your provider, as they own the logs + are the only people who can debug + fix the problem.

In other words, there's nothing you can do to resolve this problem, as it's the service providers problem.
Fractional CTO
Distinguished Expert 2018
Commented:
Workaround: The workaround for this problem tends to be ugly. Usually something like this...

1) Fetch some number of records, say 100 or 1000.

2) Wait some period of time, say 1-5 seconds.

3) Repeat till you have all your records.

4) During fetches (#1 above), process error codes + if you get a 502, then start a backoff process doubling wait time, as in 1 second, then 2 seconds, then 4/8/16/32... etc... till you hit some top limit, say 1-10 minutes.

In other words, you keep hammering your service provider with different wait times between calls, hoping your service provider's API system recovers.

Tip: This may seem ugly + is very common code, as most service providers API systems are seriously glitchy (work intermittently).

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial