mafintosh / hyperdb

Distributed scalable database
MIT License
752 stars 75 forks source link

Use Object.assign to ensure opts isn't mutated #145

Closed jimpick closed 5 years ago

jimpick commented 5 years ago

Some users may re-use the opts object passed as a parameter, which results in surprising behaviour protocol errors after multiple calls to .replicate() eg. random errors such as:

Only 128 feeds currently supported. Remote sent invalid feed message Remote message is larger than 8MB (max allowed)

There was also an instance of the opts object in the constructor being mutated as well, so added an Object.assign for that as well.

jimpick commented 5 years ago

Here was the original gist from the #dat irc channel that exhibited the issue:

https://gist.github.com/fsteff/62afca979806bfbca1ced9bd3b0d7563

jimpick commented 5 years ago

@reconbot Object.freeze() is a great idea. I just tried it, but it seems it only throws if I add 'use strict'; into the code. The funny thing is that without 'use strict'; - the freeze actually makes the test pass!

mafintosh commented 5 years ago

3.4.0 !