# Application Sporadically Down With 502

**URL:** <https://community.fly.io/t/application-sporadically-down-with-502/14824>\
**Category:** JavaScript\
**Tags:** sqlite, nodejs, litefs, login-only\
**Created:** [August 15, 2023, 5:00pm UTC](https://community.fly.io/t/application-sporadically-down-with-502/14824 "2023-08-15T17:00:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![john-waysoftware](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@john-waysoftware](https://community.fly.io/u/john-waysoftware)\
**Post date:** [August 15, 2023, 5:00pm UTC](https://community.fly.io/t/application-sporadically-down-with-502/14824/1 "2023-08-15T17:00:36Z")

</div>

Hello! I have a Nest.js application and just yesterday started experiencing some confusing issues. I am running litefs with the proxy server and just yesterday I scaled the app to the shared-cpu-2x vm and added an additional machine to the primary region. Yesterday I added redis (upstash) and the timing there feels a little suspicious.

A brief description of the issue:

- Fresh deploys work fine for a period of time
- After some time, if I refresh the page, the request hangs and eventually receives a 502 (health checks for the application server and the litefs proxy I added this morning still seem to be passing at this point)  
 ![proxy_timeout_with_server_health](https://global.discourse-cdn.com/fly1/original/3X/5/6/569abee619ddb407fdac50cf1a676796ea552e97.png)
- After some time the application seems to restart and service resumes. It should be noted that during the downtime, I can still access the site via an incognito session or different browser session. I can also access the site via the fly url link from the dashboard.

I am a bit at a loss and would greatly appreciate some help! Happy to provide any additional context as well.

fly.toml

 ![bfc_fly_toml2](https://global.discourse-cdn.com/fly1/original/3X/1/f/1f3ac5ecc9e62e4574329fbf3bfe7526dab08048.png)  
litefs.yml  
 ![bfc_litefs](https://global.discourse-cdn.com/fly1/original/3X/8/c/8c5a59d87e01bb1ca516d6b0f375a2d68a5b002f.png)

---

<div class="post-metadata">

**Author:** ![john-waysoftware](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@john-waysoftware](https://community.fly.io/u/john-waysoftware)\
**Post date:** [August 15, 2023, 7:46pm UTC](https://community.fly.io/t/application-sporadically-down-with-502/14824/2 "2023-08-15T19:46:02Z")

</div>

Update - after more carefully reviewing the litefs proxy documentation, I realized that the internal port needed to be mapped to the litefs proxy port. Attached is an updated fly.toml but I am still experiencing this issue.

 ![updated_fly_toml](https://global.discourse-cdn.com/fly1/original/3X/0/4/04ab7af41bca8f995b010713d31a8422f00bd1ee.png)

---

<div class="post-metadata">

**Author:** ![benbjohnson](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/benbjohnson/32/50901_2.png) [@benbjohnson](https://community.fly.io/u/benbjohnson)\
**Post date:** [August 15, 2023, 8:28pm UTC](https://community.fly.io/t/application-sporadically-down-with-502/14824/3 "2023-08-15T20:28:56Z")

</div>

Are you seeing anything unusual in `fly logs`? Are you able to run `fly ssh console` to go into the VM and curl `localhost:8080` from there?

---

<div class="post-metadata">

**Author:** ![john-waysoftware](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@john-waysoftware](https://community.fly.io/u/john-waysoftware)\
**Post date:** [August 16, 2023, 12:26am UTC](https://community.fly.io/t/application-sporadically-down-with-502/14824/4 "2023-08-16T00:26:54Z")

</div>

Thanks for the response @benbjohnson! I just tried and can successfully curl localhost:8080. Previously I saw an error around redis throwing an error which I wasn’t handling, but after addressing that issue, I am still experiencing the behavior. I consistently see an error that the proxy server had a connection timeout.

 ![proxy_timeout](https://global.discourse-cdn.com/fly1/original/3X/1/4/14c77a99edc49061e8b4456608688b0054e9f8d4.png)

Edit - still getting a redis error but yet unsure what is going on or if it’s related. I am just trying to use upstash redis as a session store with an implementation almost exactly to their docs: [Express Session with Serverless Redis - Upstash Documentation](https://upstash.com/docs/redis/tutorials/express_session)

 ![redis_error](https://global.discourse-cdn.com/fly1/original/3X/e/2/e2a4d82647df82ac595369de4081f203170926ea.png)

---

<div class="post-metadata">

**Author:** ![john-waysoftware](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@john-waysoftware](https://community.fly.io/u/john-waysoftware)\
**Post date:** [August 17, 2023, 10:10pm UTC](https://community.fly.io/t/application-sporadically-down-with-502/14824/5 "2023-08-17T22:10:53Z")

</div>

In case it helps somebody else, I believe this issue to be resolved. I opted to migrate from the ioredis client to node-redis with a pingInterval configured to keep the redis connection alive. I found these two other threads very helpful:

- [Upstash Redis and "could not send HTTP request to instance: connection error: timed out" logs](https://community.fly.io/t/upstash-redis-and-could-not-send-http-request-to-instance-connection-error-timed-out-logs/10104)
- [Upstash - Redis not reachable sometimes - #7 by jsierles](https://community.fly.io/t/upstash-redis-not-reachable-sometimes/9993/7)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [August 19, 2023, 10:11pm UTC](https://community.fly.io/t/application-sporadically-down-with-502/14824/6 "2023-08-19T22:11:41Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
