holepunchto / hypercore

Hypercore is a secure, distributed append-only log.
https://docs.holepunch.to
MIT License
2.57k stars 183 forks source link

Hypercore not found in version 9.7.5 #290

Closed flash0591 closed 3 years ago

flash0591 commented 3 years ago

I have a small hypercore-example:

var hypercore = require('hypercore');

var feed = hypercore('./single-chat-feed', {
    valueEncoding: 'json',
    // createIfMissing: false
});

var stream = feed.createReadStream({live: true});

stream.on('data', (chunk) => {
    console.log(`Received message: ${JSON.stringify(chunk)}`);
});

process.stdin.on('data', function (data) {
    feed.append({
        type: 'chat-message',
        nickname: 'testuser',
        text: data.toString().trim(),
        timestamp: new Date().toISOString()
    });
});

With Hypercore version >= 9.7.5 on every run the data-file is overwritten and starts with sequence 0 again. Setting createIfMissing: false leads to error Error: No hypercore is stored here. When I switch to hypercore version <9.7.5 in package.json the example above works fine and new data is appended to the already existing data. I would have expected this behaviour for current version, too.

mafintosh commented 3 years ago

Can you explain a bit more what error you are seeing? I just tried your example and it works fine for me, data gets appended and the length grows as expected

flash0591 commented 3 years ago

With createIfMissing: true I do not see any error. It just overrides the lines in data file (see bottom of comment), key file etc. With createIfMissing: false I get the following error:

events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: No hypercore is stored here
    at onsignature (C:\projectpath\node_modules\hypercore\index.js:492:37)
    at onopen (C:\projectpath\node_modules\hypercore\index.js:485:30)
    at done (C:\projectpath\node_modules\hypercore\lib\storage.js:314:10)
    at C:\projectpath\node_modules\hypercore\lib\storage.js:289:9
    at Request.loop [as _callback] (C:\projectpath\node_modules\hypercore\lib\storage.js:402:25)
    at Request.callback (C:\projectpath\node_modules\random-access-storage\index.js:173:8)
    at onread (C:\projectpath\node_modules\random-access-file\index.js:83:31)
    at FSReqCallback.wrapper [as oncomplete] (fs.js:520:5)
Emitted 'error' event on Feed instance at:
    at onerror (C:\projectpath\node_modules\hypercore\index.js:147:19)
    at Feed.onopen (C:\projectpath\node_modules\nanoresource\emitter.js:124:39)
    at C:\projectpath\node_modules\hypercore\index.js:1440:5
    at Request.done [as _callback] (C:\projectpath\node_modules\hypercore\lib\storage.js:232:5)
    at Request.callback (C:\projectpath\node_modules\random-access-storage\index.js:173:8)
    at onclose (C:\projectpath\node_modules\random-access-file\index.js:120:9)
    at FSReqCallback.oncomplete (fs.js:156:23)

Running with NodeJS Version 12.19.0 on a Windows 7 machine as well as NodeJS Version 14.16.0 on a Windows 10 machine. Same error.

data file after first run for example:

{"type":"chat-message","nickname":"testuser","text":"fasfas","timestamp":"2021-03-10T18:26:22.850Z"}
{"type":"chat-message","nickname":"testuser","text":"dsa","timestamp":"2021-03-10T18:26:23.553Z"}
{"type":"chat-message","nickname":"testuser","text":"asdas","timestamp":"2021-03-10T18:26:24.521Z"}
{"type":"chat-message","nickname":"testuser","text":"dsa","timestamp":"2021-03-10T18:26:25.649Z"}

After second run, with just entering one message before closing:

{"type":"chat-message","nickname":"testuser","text":"ijfisfdifs","timestamp":"2021-03-10T18:27:13.086Z"}
pe":"chat-message","nickname":"testuser","text":"dsa","timestamp":"2021-03-10T18:26:23.553Z"}
{"type":"chat-message","nickname":"testuser","text":"asdas","timestamp":"2021-03-10T18:26:24.521Z"}
{"type":"chat-message","nickname":"testuser","text":"dsa","timestamp":"2021-03-10T18:26:25.649Z"}
mafintosh commented 3 years ago

Thanks. For 9.7.5, when it works for you, can you see in node_modules which version of hypercore-default-storage it installs?

flash0591 commented 3 years ago

For 9.7.5 it does NOT work. For smaller versions (for example 9.7.4) it works. hypercore 9.7.5 installed hypercore-default-storage in version 1.1.0. hypercore 9.7.4 also installed the same version.

mafintosh commented 3 years ago

Thanks, can you try the latest one I just released 9.9.1? I think we have a regression in a dep on Windows that I just disabled temporarily while we investigate

flash0591 commented 3 years ago

Great, with 9.9.1 it works fine.

mafintosh commented 3 years ago

Awesome, thanks for your help. Appreciate the heads up.