Error: Connection to remote host was lost | fyers-apiv3

@Z4PBvkQGyF

I am getting this error upon running fyers-apiv3. Got this briefly for 30-40 mins yesterday, later it got fixed itself and it reappeared today.
Unable to attach the log file, so pasted it.

====================================================================================================
                                        	09:22
====================================================================================================

0

====================================================================================================
                                        	09:23
====================================================================================================

Error: Connection to remote host was lost.
Attempting reconnect 1 of 5...
Error: Handshake status 502 Bad Gateway -+-+- {'server': 'awselb/2.0', 'date': 'Wed, 30 Aug 2023 03:53:28 GMT', 'content-type': 'text/html', 'content-length': '122', 'connection': 'keep-alive', 'set-cookie': 'AWSALBTG=yhvCXXSYIHr3UuncZp+dCxNG1ZOteLT4pkWW9btumkgGzg4KvgHC2+HvmGYNVzGrRsdkte7aSwf508XbcVrr31LZGiSVxv5bbu2TmL6eGiLKJLdl37ts85e6DaO+MSjDrcyRBvff2/v80pT987cysYbez9wK0kuoO0e1XlTooXFe; Expires=Wed, 06 Sep 2023 03:53:28 GMT; Path=/; AWSALBTGCORS=yhvCXXSYIHr3UuncZp+dCxNG1ZOteLT4pkWW9btumkgGzg4KvgHC2+HvmGYNVzGrRsdkte7aSwf508XbcVrr31LZGiSVxv5bbu2TmL6eGiLKJLdl37ts85e6DaO+MSjDrcyRBvff2/v80pT987cysYbez9wK0kuoO0e1XlTooXFe; Expires=Wed, 06 Sep 2023 03:53:28 GMT; Path=/; SameSite=None; Secure'} -+-+- b'\r\n502 Bad Gateway\r\n\r\n
# 502 Bad Gateway
\r\n\r\n\r\n'
Attempting reconnect 2 of 5...
Error: Handshake status 502 Bad Gateway -+-+- {'server': 'awselb/2.0', 'date': 'Wed, 30 Aug 2023 03:53:38 GMT', 'content-type': 'text/html', 'content-length': '122', 'connection': 'keep-alive', 'set-cookie': 'AWSALBTG=8tjie2M4AGkBT3AqSHUmozgfDueM3c9ukNkuDGLF2k7CkCZAVAf7f+A4pYR+89aiUOFWQwII/ZlJnUn+PrT6V+SQNJopNvKHAGxzZKJiCGgv8gf0SwXKnBUXQKP0mv2px17H7VInvI2ztolHTOtT+uTUUlt1vn1dWpkHjP/STNKg; Expires=Wed, 06 Sep 2023 03:53:38 GMT; Path=/; AWSALBTGCORS=8tjie2M4AGkBT3AqSHUmozgfDueM3c9ukNkuDGLF2k7CkCZAVAf7f+A4pYR+89aiUOFWQwII/ZlJnUn+PrT6V+SQNJopNvKHAGxzZKJiCGgv8gf0SwXKnBUXQKP0mv2px17H7VInvI2ztolHTOtT+uTUUlt1vn1dWpkHjP/STNKg; Expires=Wed, 06 Sep 2023 03:53:38 GMT; Path=/; SameSite=None; Secure'} -+-+- b'\r\n502 Bad Gateway\r\n\r\n
# 502 Bad Gateway
\r\n\r\n\r\n'
Attempting reconnect 3 of 5...
Error: Handshake status 502 Bad Gateway -+-+- {'server': 'awselb/2.0', 'date': 'Wed, 30 Aug 2023 03:53:48 GMT', 'content-type': 'text/html', 'content-length': '122', 'connection': 'keep-alive', 'set-cookie': 'AWSALBTG=Sq7a2z93vj6FkqTdM5mtL2QkCAVaUNgVj2LRpSTcfiDJJex7OlSRcIGKKvhLFTajbt5XaV+gzyToS6xHxXyYM0ENywBsKaxl9Y4Yw5+/ctLjzk5PFXu9H81uwMzS8ytdGcqfABsj19rJhVz+c4zkJroGpNNajQ2JS+rpTqbLB13S; Expires=Wed, 06 Sep 2023 03:53:48 GMT; Path=/; AWSALBTGCORS=Sq7a2z93vj6FkqTdM5mtL2QkCAVaUNgVj2LRpSTcfiDJJex7OlSRcIGKKvhLFTajbt5XaV+gzyToS6xHxXyYM0ENywBsKaxl9Y4Yw5+/ctLjzk5PFXu9H81uwMzS8ytdGcqfABsj19rJhVz+c4zkJroGpNNajQ2JS+rpTqbLB13S; Expires=Wed, 06 Sep 2023 03:53:48 GMT; Path=/; SameSite=None; Secure'} -+-+- b'\r\n502 Bad Gateway\r\n\r\n
# 502 Bad Gateway
\r\n\r\n\r\n'
Attempting reconnect 4 of 5...
0

====================================================================================================
                                        	09:24
====================================================================================================

Error: Handshake status 502 Bad Gateway -+-+- {'server': 'awselb/2.0', 'date': 'Wed, 30 Aug 2023 03:53:59 GMT', 'content-type': 'text/html', 'content-length': '122', 'connection': 'keep-alive', 'set-cookie': 'AWSALBTG=VbbK0xc+UejODQX0YFXYn0dtdo0/rxf+Z1MTqurXeLcSWTYxJLi7/8VRMtNBFIrXcRI+RnyYa+NLKRM45a+fZuh8PKvyp/hKPzdwwE5RzpqS1uAeuC7TAf9wkltTxAaxXPeoRGezDcTvBHrWWIUzTvwYCEkRduFpVIULwI7IyYgX; Expires=Wed, 06 Sep 2023 03:53:59 GMT; Path=/; AWSALBTGCORS=VbbK0xc+UejODQX0YFXYn0dtdo0/rxf+Z1MTqurXeLcSWTYxJLi7/8VRMtNBFIrXcRI+RnyYa+NLKRM45a+fZuh8PKvyp/hKPzdwwE5RzpqS1uAeuC7TAf9wkltTxAaxXPeoRGezDcTvBHrWWIUzTvwYCEkRduFpVIULwI7IyYgX; Expires=Wed, 06 Sep 2023 03:53:59 GMT; Path=/; SameSite=None; Secure'} -+-+- b'\r\n502 Bad Gateway\r\n\r\n
# 502 Bad Gateway
\r\n\r\n\r\n'
Attempting reconnect 5 of 5...
Error: {'type': 'sub', 'code': 11011, 'message': 'subscription failed', 's': 'error'}
Error: {'type': 'sub', 'code': 11011, 'message': 'subscription failed', 's': 'error'}

Hi @immaturetrader

please create an new access token and then try it.
it is because of your old access token. Just informing you, you have to generate access token everyday
Thanks

Hi @Z4PBvkQGyF

I have created a new access_token and reran the program, still the problem persists.

I have created two subscriptions symboldata, general(all). Upon debuging I get this error from order_ws.py -> on_error() , Later the general subscription fails, but the symboldata subscription works fine.

Update: I have assigned seperated methods to shared func calls, Eg: on_error() → is seperated for both subscriptions with different names. When I run Individual subscriptions it works fine, but when I run them together I get the error.

Hi @immaturetrader

Can you give 2 different name and use callback function where you want to call.
My means if two function u are using for error then call respectively where you want to use.

Hope it will help

Yes @Z4PBvkQGyF, I have assigned different names for the functions, and still the problem persists. Besides, I see there is not reconnect for order_ws as provided for data_ws. So I tried manually callling to connect the general socket using self.general_fyers.connect(), this makes the code messy as it tries to connect every other minute upon error.

I am unable to attach the sample .py file for your testing. Please provide me an email so I can forward you the code.

Hi @immaturetrader
Once can you contact our support team, They will take you on remote.
I will help you by seeing your code>
Thank you

Hi @Z4PBvkQGyF
I have shared the code with support, ticket no: 1114441. I will create a new discussion and ask the community to try the code, so they can debug if any issue.
Below is the latest error screenshot, ran 31-08-2023.

Besides The CPU & RAM usage has increased for v3 causing my zerodha and upstox API’s to bottleneck, AWS EC2 charges hefty for larger config, so for now would be sticking to v2.

Jump in CPU v2(13.5% constant) => v3(20-32%)

Jump in RAM v2(70-110MB) => v3(peak of 225) with file compression turned off.