David Valdivieso
David Valdivieso

Reputation: 481

Redis ( node-redis ) - Unhandled 'error' event

CLIENT: 3.0.2 REDIS: 5.0.3

var redis__create_ping = ( client ) => {
        client.ping = setInterval(( )=>{
                let timestamp = ( new Date() ).getTime();
                client.instance.ping(  (error, pong ) => {
                        if( error ){
                                console.error( '\n<PING ERROR>', client.name, client.index );
                                console.error( error );
                        }
                        else {
                                if( __.DEBUG ){
                                        console.log( '\n<PING>', client.name, client.index, (new Date()).getTime() - timestamp );
                                }
                        };
                });
        },  30000);
};

var redis__connect = ( args , success, fail ) => {
        let { index, name } = args;
        let client = { name, index };
        let host = ___.REDIS.HOST;
        let port = ___.REDIS.PORT;
        let cli = redis.createClient({ host, port, db: index, socket_keepalive: true });
        cli.on('connect',  ready => {
                if( __.DEBUG ) console.info('\n<CONNECT>', name, index  );
                client.instance = cli;
                redis__create_ping( client );
                CLIENTS[name] = client;
                success( true );
        });

        cli.on('ready', () => {
                if( __.DEBUG ) console.info( '\n<READY>', name, index );
        });

        cli.on('reconnecting', () => {
                if( __.DEBUG ) console.info( '\n<RECONNECTING>', name, index );
        });

        cli.on('end', () => {
                if( __.DEBUG ) console.info('\n<END>', name, index  );
        });

        cli.on('uncaughtException',  error  => {
                console.error('\n<UNCAUGHT-EXCEPTION>', name, index  );
                console.error( error  );
        });

        cli.on('error', error => {
                console.error('\n<ERROR>', name, index  );
                console.error( error );
        });
};

LOG

...
2021-01-27 15:59:42.472 EST<PING> REDIS_CLIENT_BLOCKED_NUMBERS_WRITE 11 4
Default
2021-01-27 15:59:42.480 ESTevents.js:292
Default
2021-01-27 15:59:42.480 EST throw er; // Unhandled 'error' event
Default
2021-01-27 15:59:42.480 EST ^
Default
2021-01-27 15:59:42.480 EST
Default
2021-01-27 15:59:42.480 ESTError: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
Default
2021-01-27 15:59:42.480 ESTEmitted 'error' event on RedisClient instance at:
Default
2021-01-27 15:59:42.480 EST at RedisClient.on_error (/opt/app/node_modules/redis/index.js:341:14)
Default
2021-01-27 15:59:42.480 EST at Socket.<anonymous> (/opt/app/node_modules/redis/index.js:222:14)
Default
2021-01-27 15:59:42.480 EST at Socket.emit (events.js:315:20)
Default
2021-01-27 15:59:42.480 EST at emitErrorNT (internal/streams/destroy.js:106:8)
Default
2021-01-27 15:59:42.480 EST at emitErrorCloseNT (internal/streams/destroy.js:74:3)
Default
2021-01-27 15:59:42.480 EST at processTicksAndRejections (internal/process/task_queues.js:80:21) {
Default
2021-01-27 15:59:42.480 EST errno: -104,
Default
2021-01-27 15:59:42.480 EST code: 'ECONNRESET',
Default
2021-01-27 15:59:42.480 EST syscall: 'read'
Default
2021-01-27 15:59:42.480 EST}
Warning
2021-01-27 15:59:46.579 ESTContainer called exit(1).

I'm totally aware that something inside GCLOUD network could be wrong or even in the REDIS-SERVER. But why I can't handle this error? it keeps killing my app.

Upvotes: 0

Views: 1095

Answers (1)

David Valdivieso
David Valdivieso

Reputation: 481

Deep Inside my code I had a duplicate() connection without an error handler.

Upvotes: 0

Related Questions