title: Heroku Redis closing socket unexpectedly within shopify app
body: <p>I am new to shopify api, what I have done is create node app with the following details:<br />
  shopify api V5.0.1<br />
  using redis as SessionStorage<br />
  deployed to heroku<br />
  shopify cli V2.22<br />
  Heroku Data for Redis</p>
  <p>and here is the log from heroku using this command <code>heroku logs -t --app</code>&lt;app_name_in_heroku&gt;`</p>
  
    See log
  <pre><code>2022-08-22T02:53:05.000000+00:00 app[heroku-redis]: source=REDIS addon=redis-closed-31837 sample#active-connections=2 sample#load-avg-1m=0.395 sample#load-avg-5m=0.29 sample#load-avg-15m=0.235 sample#read-iops=0 sample#write-iops=0 sample#memory-total=16085852kB sample#memory-free=10200488kB sample#memory-cached=2958216kB sample#memory-redis=355704bytes sample#hit-rate=1 sample#evicted-keys=0
  2022-08-22T02:57:43.000000+00:00 app[heroku-redis]: source=REDIS addon=redis-closed-31837 sample#active-connections=2 sample#load-avg-1m=0.315 sample#load-avg-5m=0.375 sample#load-avg-15m=0.28 sample#read-iops=0 sample#write-iops=0 sample#memory-total=16085852kB sample#memory-free=10199724kB sample#memory-cached=2958228kB sample#memory-redis=355704bytes sample#hit-rate=1 sample#evicted-keys=0
  2022-08-22T02:57:43.000000+00:00 app[heroku-redis]: source=REDIS addon=redis-closed-31837 sample#active-connections=2 sample#load-avg-1m=0.155 sample#load-avg-5m=0.285 sample#load-avg-15m=0.26 sample#read-iops=0 sample#write-iops=0 sample#memory-total=16085852kB sample#memory-free=10200236kB sample#memory-cached=2958236kB sample#memory-redis=355672bytes sample#hit-rate=1 sample#evicted-keys=0
  2022-08-22T02:58:36.080444+00:00 app[web.1]: node:events:491
  2022-08-22T02:58:36.080453+00:00 app[web.1]: throw er; // Unhandled 'error' event
  2022-08-22T02:58:36.080454+00:00 app[web.1]: ^
  2022-08-22T02:58:36.080454+00:00 app[web.1]:
  2022-08-22T02:58:36.080455+00:00 app[web.1]: SocketClosedUnexpectedlyError: Socket closed unexpectedly
  2022-08-22T02:58:36.080456+00:00 app[web.1]: at Socket.&lt;anonymous&gt; (/app/node_modules/@redis/client/dist/lib/client/socket.js:156:118)
  2022-08-22T02:58:36.080456+00:00 app[web.1]: at Object.onceWrapper (node:events:628:26)
  2022-08-22T02:58:36.080457+00:00 app[web.1]: at Socket.emit (node:events:513:28)
  2022-08-22T02:58:36.080457+00:00 app[web.1]: at TCP.&lt;anonymous&gt; (node:net:757:14)
  2022-08-22T02:58:36.080457+00:00 app[web.1]: Emitted 'error' event on Commander instance at:
  2022-08-22T02:58:36.080458+00:00 app[web.1]: at RedisSocket.&lt;anonymous&gt; (/app/node_modules/@redis/client/dist/lib/client/index.js:344:14)
  2022-08-22T02:58:36.080458+00:00 app[web.1]: at RedisSocket.emit (node:events:513:28)
  2022-08-22T02:58:36.080459+00:00 app[web.1]: at RedisSocket._RedisSocket_onSocketError (/app/node_modules/@redis/client/dist/lib/client/socket.js:179:10)
  2022-08-22T02:58:36.080460+00:00 app[web.1]: at Socket.&lt;anonymous&gt; (/app/node_modules/@redis/client/dist/lib/client/socket.js:156:107)
  2022-08-22T02:58:36.080460+00:00 app[web.1]: at Object.onceWrapper (node:events:628:26)
  2022-08-22T02:58:36.080460+00:00 app[web.1]: at Socket.emit (node:events:513:28)
  2022-08-22T02:58:36.080461+00:00 app[web.1]: at TCP.&lt;anonymous&gt; (node:net:757:14)
  2022-08-22T02:58:36.080466+00:00 app[web.1]:
  2022-08-22T02:58:36.080467+00:00 app[web.1]: Node.js v18.7.0
  2022-08-22T02:58:36.223443+00:00 heroku[web.1]: Process exited with status 1
  2022-08-22T02:58:36.431160+00:00 heroku[web.1]: State changed from up to crashed
  2022-08-22T02:58:36.434346+00:00 heroku[web.1]: State changed from crashed to starting
  2022-08-22T02:58:40.417402+00:00 heroku[web.1]: Starting process with command `npm start`
  2022-08-22T02:58:42.045346+00:00 app[web.1]:
  2022-08-22T02:58:42.045359+00:00 app[web.1]: &gt; start
  2022-08-22T02:58:42.045359+00:00 app[web.1]: &gt; npm run serve
  2022-08-22T02:58:42.045360+00:00 app[web.1]:
  2022-08-22T02:58:42.360327+00:00 app[web.1]:
  2022-08-22T02:58:42.360333+00:00 app[web.1]: &gt; preserve
  2022-08-22T02:58:42.360333+00:00 app[web.1]: &gt; npm run build
  2022-08-22T02:58:42.360334+00:00 app[web.1]:
  2022-08-22T02:58:42.663352+00:00 app[web.1]:
  2022-08-22T02:58:42.663364+00:00 app[web.1]: &gt; build
  2022-08-22T02:58:42.663366+00:00 app[web.1]: &gt; npm run build:client
  2022-08-22T02:58:42.663366+00:00 app[web.1]:
  2022-08-22T02:58:42.969492+00:00 app[web.1]:
  2022-08-22T02:58:42.969499+00:00 app[web.1]: &gt; build:client
  2022-08-22T02:58:42.969500+00:00 app[web.1]: &gt; vite build --outDir dist/client
  2022-08-22T02:58:42.969500+00:00 app[web.1]:
  2022-08-22T02:58:43.361517+00:00 app[web.1]: vite v2.9.8 building for production...
  2022-08-22T02:58:43.418520+00:00 app[web.1]: transforming...
  2022-08-22T02:58:51.309037+00:00 app[web.1]: ✓ 1478 modules transformed.
  2022-08-22T02:58:52.060605+00:00 app[web.1]: rendering chunks...
  2022-08-22T02:58:52.068929+00:00 app[web.1]: dist/client/assets/eromman_logo.6b39893a.png   8.82 KiB
  2022-08-22T02:58:52.071195+00:00 app[web.1]: dist/client/index.html                         0.29 KiB
  2022-08-22T02:58:52.079983+00:00 app[web.1]: dist/client/assets/index.9ac88508.css          330.02 KiB / gzip: 38.73 KiB
  2022-08-22T02:58:52.102140+00:00 app[web.1]: dist/client/assets/index.f69ec157.js           522.69 KiB / gzip: 144.56 KiB
  2022-08-22T02:58:52.102350+00:00 app[web.1]:
  2022-08-22T02:58:52.102350+00:00 app[web.1]: (!) Some chunks are larger than 500 KiB after minification. Consider:
  2022-08-22T02:58:52.102351+00:00 app[web.1]: - Using dynamic import() to code-split the application
  2022-08-22T02:58:52.102353+00:00 app[web.1]: - Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/guide/en/#outputmanualchunks
  2022-08-22T02:58:52.102353+00:00 app[web.1]: - Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
  2022-08-22T02:58:52.145873+00:00 app[web.1]:
  2022-08-22T02:58:52.145874+00:00 app[web.1]: &gt; serve
  2022-08-22T02:58:52.145875+00:00 app[web.1]: &gt; cross-env NODE_ENV=production node server/index.js
  2022-08-22T02:58:52.145876+00:00 app[web.1]:
  2022-08-22T02:58:53.208466+00:00 heroku[web.1]: State changed from starting to up
  2022-08-22T03:02:17.000000+00:00 app[heroku-redis]: source=REDIS addon=redis-closed-31837 sample#active-connections=2 sample#load-avg-1m=0.155 sample#load-avg-5m=0.26 sample#load-avg-15m=0.255 sample#read-iops=0 sample#write-iops=0 sample#memory-total=16085852kB sample#memory-free=10198040kB sample#memory-cached=2958376kB sample#memory-redis=355672bytes sample#hit-rate=1 sample#evicted-keys=0
  2022-08-22T03:02:17.000000+00:00 app[heroku-redis]: source=REDIS addon=redis-closed-31837 sample#active-connections=2 sample#load-avg-1m=0.31 sample#load-avg-5m=0.29 sample#load-avg-15m=0.27 sample#read-iops=0 sample#write-iops=0 sample#memory-total=16085852kB sample#memory-free=10199328kB sample#memory-cached=2958376kB sample#memory-redis=355672bytes sample#hit-rate=1 sample#evicted-keys=0
  2022-08-22T03:07:14.000000+00:00 app[heroku-redis]: source=REDIS addon=redis-closed-31837 sample#active-connections=2 sample#load-avg-1m=0.175 sample#load-avg-5m=0.25 sample#load-avg-15m=0.26 sample#read-iops=0 sample#write-iops=0 sample#memory-total=16085852kB sample#memory-free=10200780kB sample#memory-cached=2958388kB sample#memory-redis=355672bytes sample#hit-rate=1 sample#evicted-keys=0
  2022-08-22T03:07:14.000000+00:00 app[heroku-redis]: source=REDIS addon=redis-closed-31837 sample#active-connections=2 sample#load-avg-1m=0.1 sample#load-avg-5m=0.185 sample#load-avg-15m=0.23 sample#read-iops=0 sample#write-iops=0 sample#memory-total=16085852kB sample#memory-free=10199220kB sample#memory-cached=2958524kB sample#memory-redis=355672bytes sample#hit-rate=1 sample#evicted-keys=0
  2022-08-22T03:11:57.000000+00:00 app[heroku-redis]: source=REDIS addon=redis-closed-31837 sample#active-connections=2 sample#load-avg-1m=0.085 sample#load-avg-5m=0.15 sample#load-avg-15m=0.21 sample#read-iops=0 sample#write-iops=0 sample#memory-total=16085852kB sample#memory-free=10199936kB sample#memory-cached=2958536kB sample#memory-redis=355672bytes sample#hit-rate=1 sample#evicted-keys=0
  2022-08-22T03:13:53.045639+00:00 app[web.1]: node:events:491
  2022-08-22T03:13:53.045648+00:00 app[web.1]: throw er; // Unhandled 'error' event
  2022-08-22T03:13:53.045648+00:00 app[web.1]: ^
  2022-08-22T03:13:53.045648+00:00 app[web.1]:
  2022-08-22T03:13:53.045649+00:00 app[web.1]: SocketClosedUnexpectedlyError: Socket closed unexpectedly
  2022-08-22T03:13:53.045650+00:00 app[web.1]: at Socket.&lt;anonymous&gt; (/app/node_modules/@redis/client/dist/lib/client/socket.js:156:118)
  2022-08-22T03:13:53.045650+00:00 app[web.1]: at Object.onceWrapper (node:events:628:26)
  2022-08-22T03:13:53.045651+00:00 app[web.1]: at Socket.emit (node:events:513:28)
  2022-08-22T03:13:53.045651+00:00 app[web.1]: at TCP.&lt;anonymous&gt; (node:net:757:14)
  2022-08-22T03:13:53.045651+00:00 app[web.1]: Emitted 'error' event on Commander instance at:
  2022-08-22T03:13:53.045652+00:00 app[web.1]: at RedisSocket.&lt;anonymous&gt; (/app/node_modules/@redis/client/dist/lib/client/index.js:344:14)
  2022-08-22T03:13:53.045652+00:00 app[web.1]: at RedisSocket.emit (node:events:513:28)
  2022-08-22T03:13:53.045653+00:00 app[web.1]: at RedisSocket._RedisSocket_onSocketError (/app/node_modules/@redis/client/dist/lib/client/socket.js:179:10)
  2022-08-22T03:13:53.045653+00:00 app[web.1]: at Socket.&lt;anonymous&gt; (/app/node_modules/@redis/client/dist/lib/client/socket.js:156:107)
  2022-08-22T03:13:53.045653+00:00 app[web.1]: at Object.onceWrapper (node:events:628:26)
  2022-08-22T03:13:53.045654+00:00 app[web.1]: at Socket.emit (node:events:513:28)
  2022-08-22T03:13:53.045654+00:00 app[web.1]: at TCP.&lt;anonymous&gt; (node:net:757:14)
  2022-08-22T03:13:53.045659+00:00 app[web.1]:
  2022-08-22T03:13:53.045659+00:00 app[web.1]: Node.js v18.7.0
  2022-08-22T03:13:53.674235+00:00 heroku[web.1]: State changed from up to crashed
  2022-08-22T03:13:53.677381+00:00 heroku[web.1]: State changed from crashed to starting
  2022-08-22T03:13:53.486062+00:00 heroku[web.1]: Process exited with status 1
  2022-08-22T03:13:59.017503+00:00 heroku[web.1]: Starting process with command `npm start`
  2022-08-22T03:14:00.918467+00:00 app[web.1]:
  2022-08-22T03:14:00.918479+00:00 app[web.1]: &gt; start
  2022-08-22T03:14:00.918479+00:00 app[web.1]: &gt; npm run serve
  2022-08-22T03:14:00.918479+00:00 app[web.1]:
  2022-08-22T03:14:02.061437+00:00 app[web.1]:
  2022-08-22T03:14:02.061449+00:00 app[web.1]: &gt; build:client
  2022-08-22T03:14:02.061450+00:00 app[web.1]: &gt; vite build --outDir dist/client
  </code></pre>
  
  <p>As you can see the error is<br />
  node:events:491<br />
  throw er; // Unhandled 'error' event<br />
  SocketClosedUnexpectedlyError: Socket closed unexpectedly</p>
  <p>and the weired thing is heroku immediatly rebuild the app?!!! I think it should only restart. am i right?</p>
  <p>My question is how to know the cause of this error??</p>
  <p>how to resolve this error?
  Because my app got rejected in final review because of this error since shopify app send me below screenshot while the are reviewing my app
  <img src="https://shopify.click/22-08-81747-93302.png" alt="" /></p>
  <p>Yes heroku is displaying this error but after a while(after rebuild) the app again because accessible and works fine
  and after successfull installation by 1 min the error occur and heroku rebuild the app again.</p>
  <p>Any help is appreciated and thanks in advance</p>