thedevs-network / kutt

Free Modern URL Shortener.
https://kutt.it
MIT License
8.42k stars 1.09k forks source link

Crashing way too often #375

Open shuat opened 4 years ago

shuat commented 4 years ago

My application keeps crashing with the following message. Why should a connection reset cause the application to crash? I have other applications using that redis and they are doing fine.


> Ready on http://localhost:80
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: Redis connection to *.*.*.*:6379 failed - read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:205:27)
Emitted 'error' event on RedisClient instance at:
    at RedisClient.on_error (/usr/src/app/node_modules/redis/index.js:406:14)
    at Socket.<anonymous> (/usr/src/app/node_modules/redis/index.js:279:14)
    at Socket.emit (events.js:315:20)
    at Socket.EventEmitter.emit (domain.js:483:12)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! kutt@2.3.16 start: `npm run migrate && NODE_ENV=production node production-server/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the kutt@2.3.16 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-08-30T22_00_06_007Z-debug.log```
trgwii commented 4 years ago

What could be causing the redis connection to be dropped? Is your redis instance on a different server? Is your redis instance overloaded?

Kutt depends on having a constant live connection to Redis, since it needs to query the cache FAST in large deployments. If the connection was allowed to be dropped and reconnect again that could create a significant slowdown for users during that time.

vRobM commented 3 years ago

Connection drops should not crash the app.

If a constant connection needs to be maintained, consider using a connection pool, where if any drop there are others still available for queries and new connections will be established to maintain a certain number in the pool.

MKRhere commented 3 years ago

consider using a connection pool

That wouldn't work if the Redis connection is dropped due to network reasons or the Redis server itself is going down for some reason. All connections in the pool would disconnect.