question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data corruption on `get`

See original GitHub issue

Found a strange data corruption on get.

Tried with latest redis:3 and redis:2 in docker + node version 6.3.0 and 5.12.0. Tried to bisect redis package version and found that bug is introduced in version 2.6.0.

Test to reproduce:

const assert = require('assert');

const redis = require('redis').createClient();

const data = JSON.stringify({
    "city_name": "Санкт-Петербург" // (russian language)
});
const key = 'somekey';

describe('redis', () => {

    before(done => redis.set(key, data, done));
    after(done  => redis.del(key, done));

    for (let i = 0; i < 10000; ++i) {
        it(`pass ${i}`, done => {
            redis.get(key, (err, results) => {
                assert(!err);
                assert.strictEqual(results, data);

                done();
            });
        })
    }

});

package.json:

{
  "devDependencies": {
    "mocha": "^2.5.3"
  },
  "dependencies": {
    "redis": "=2.6.0"
  }
}

Output:

    ... (skipped)
    ✓ pass 1217
    ✓ pass 1218
    1) pass 1219
    2) "after all" hook

  1219 passing (4s)
  2 failing

  1) redis pass 1219:

      Uncaught AssertionError: '{"city_name":"��анкт-Петербург"}' === '{"city_name":"Санкт-Петербург"}'
      + expected - actual

      -{"city_name":"��анкт-Петербург"}
      +{"city_name":"Санкт-Петербург"}

Failed pass number is floating. Mocha is running with -b flag to stop on the first fail, but if we test it without this flag, then it will continue to fail after first broken pass:

    ... (skipped)
    ✓ pass 2477
    ✓ pass 2478
    1) pass 2479
    2) pass 2480
    3) pass 2481
    4) pass 2482
    5) pass 2483
    ... (all passes are failed until the end)

First fail is about data corruption, next fails are about err in callback:

{ AbortError: Fatal error encountert. Command aborted. It might have been processed.
    at RedisClient.flush_and_error (/Users/silent/Projects/redis-test/node_modules/redis/index.js:350:23)
    at JavascriptRedisParser.Parser.returnFatalError (/Users/silent/Projects/redis-test/node_modules/redis/index.js:199:18)
    at handleError (/Users/silent/Projects/redis-test/node_modules/redis-parser/lib/parser.js:172:10)
    at parseType (/Users/silent/Projects/redis-test/node_modules/redis-parser/lib/parser.js:224:14)
    at JavascriptRedisParser.execute (/Users/silent/Projects/redis-test/node_modules/redis-parser/lib/parser.js:404:20)
    at Socket.<anonymous> (/Users/silent/Projects/redis-test/node_modules/redis/index.js:267:27)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:177:18)
    at Socket.Readable.push (_stream_readable.js:135:10)
    at TCP.onread (net.js:542:20)
  code: 'NR_FATAL',
  command: 'GET',
  args: [ 'somekey' ],
  origin:
   ReplyError: Protocol error, got "c" as reply type byte. Please report this.
       at parseType (/Users/silent/Projects/redis-test/node_modules/redis-parser/lib/parser.js:224:34)
       at JavascriptRedisParser.execute (/Users/silent/Projects/redis-test/node_modules/redis-parser/lib/parser.js:404:20) } undefined

or sometimes with this:

     Uncaught RangeError: out of range index
      at RangeError (native)
      at concatBuffer (node_modules/redis-parser/lib/parser.js:357:13)
      at JavascriptRedisParser.execute (node_modules/redis-parser/lib/parser.js:389:21)
      at Socket.<anonymous> (node_modules/redis/index.js:267:27)
      at readableAddChunk (_stream_readable.js:177:18)
      at Socket.Readable.push (_stream_readable.js:135:10)
      at TCP.onread (net.js:542:20)

Can’t reproduce with latin chars only. Also can’t reproduce with return_buffers: true.

Here is value via redis-cli, maybe it will be helpful:

127.0.0.1:6379> get somekey
"{\"city_name\":\"\xd0\xa1\xd0\xb0\xd0\xbd\xd0\xba\xd1\x82-\xd0\x9f\xd0\xb5\xd1\x82\xd0\xb5\xd1\x80\xd0\xb1\xd1\x83\xd1\x80\xd0\xb3\"}"

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
silentroachcommented, Jul 21, 2016

Can’t reproduce on local redis, but can reproduce while connecting to different pc in network with data string modification to more complex example.

test.zip

(just replace host with something different than your ip to work via network)

failed with first iteration, in the next you can find out of range index error.

1reaction
BridgeARcommented, Jul 21, 2016

Did you try the same without docker?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix Corrupted Database/Data Error on PS4 - EaseUS
When you get corrupted data in a game, you will see an obvious sign, as shown in the image below. PS4 data corrupted...
Read more >
Data corruption - Wikipedia
Data corruption refers to errors in computer data that occur during writing, reading, storage, transmission, or processing, which introduce unintended ...
Read more >
What Is Data Corruption? How to Fix a Corrupted Hard Drive
Data can become corrupted during writing, editing, or transfer to another drive. When a program writes incorrect data, or when something ...
Read more >
Data corruption and loss: causes and avoidance - The X Lab
A corrupted hard drive directory can cause files to apparently "go missing" and lead to further data loss or corruption, such files being...
Read more >
What Causes Hard Drive Data Corruption
To avoid hard drive damage, you should keep your drive powered off until you can get a professional evaluation from a data recovery...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found