redis / redis/node-redis

AbortError: SCAN can't be processed. The connection is already closed.

Open
#1,414 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Pending Author Input
Dominant language
TypeScript
Stars
17.6k
Forks
2k
Avg merge
2d 3h
Merged PRs (30d)
40

Description

I have just two properties:
A = anything
AA = anything

Result:
cursor 0
cursor 1
cursor 3
AbortError: SCAN can't be processed. The connection is already closed.

function scanAsync( redis, cursor, pattern, set ) {
  return new Promise( ( resolve, reject ) => {
    scan( redis, cursor, pattern, set, resolve, reject );
  } );
}

function scan( redis, cursor, pattern, set, resolve, reject ) {
  console.log( "cursor", cursor );
  // Same result if using redis.scan( cursor, 'MATCH', pattern, 'COUNT', '1', function( err, res ) {
  redis.send_command( 'scan', [ cursor, 'MATCH', pattern, 'COUNT', '1' ], function( err, res ) {
    if ( err ) {
      throw err;
    }

    // Update the cursor position for the next scan
    cursor = res[ 0 ];
    // get the SCAN result for this iteration
    var keys = res[ 1 ];

    // Result is more or less than COUNT, or no keys may be returned.
    // SCAN may return the same key multiple times.
    if ( keys.length > 0 ) {
      keys.forEach( function( key, i ) {
        set.add( key );
      } );
    }

    // An iteration starts when the cursor is set to 0
    // and terminates when the cursor returned by the server is 0.
    if ( cursor === '0' ) {
      resolve( true );
    }
    else {
      scan( redis, cursor, pattern, set, resolve, reject );
    }
  } );
}

var myResults = new Set();
var redis = require( "redis" );

scanAsync( this.redis, '0', "A*", myResults ).then( function( value ) {
  console.log( value, "myResults", myResults, Array.from( myResults ) );
}, function( err ) {
  console.log( err );
} );

The server works ok:

mine:0>scan 0 'A*' 1
"ERR syntax error"
mine:0>scan 0 MATCH A* COUNT 1

  1. "1"
    1. "AA"

mine:0>scan 1 MATCH A* COUNT 1

  1. "3"
    1. "A"

mine:0>scan 3 MATCH A* COUNT 1

  1. "0"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied JavaScript reproduction and Redis SCAN transcript. No repository file or test is named, so trace the client's SCAN callback and connection lifecycle before attempting a fix. Done means reproducing the closed-connection error and establishing a verified resolution or documented cause.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, redis
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.