Skip to content

localFileSystem data cleared #2723

Closed
Closed

Description

@tanjie9012

setting.js
contextStorage: {
default: "memory",
memory: {module: 'memory'},
file: {
module: 'localfilesystem',
config: {
//dir: "~/.node-red",
//base: "context",
//cache: true,
flushInterval: 5
}
}
}

After power failure, there is a certain probability that the context storage file data will be emptied with a length of 0. What causes this problem? Is the operation of clearing data occurred during power failure or during NR startup?

  • Node-RED version: v1.0.4
  • Node.js version: v12.16.1
  • npm version: v6.13.4
  • Platform/OS: OpenWrt v19.0.7
  • Browser:
  • running in Docker:

Activity

  1. knolleary commented on Oct 14, 2020

    @knolleary
    Member

    Hi @tanjie9012 ,

    that sounds very strange. The context LocalFileSystem module takes care not to corrupt its files. It writes updates to a temporary file and then does a rename to move the temporary file over the proper file as a final step. That should ensure we never leave the proper file in a bad state.

    The fact you are using Docker may be of interest.... what docker image are you using and how is it configure to store user data?

  2. csmale commented on Nov 18, 2020

    @csmale

    I have seen this many times running on Windows on an NTFS disk. Is it possible that the write to the temp file is not committed to disk, but the delete/rename "overtake" it in the queue somehow? The file system operations behind delete and rename are more complex.
    The annoying thing is that it stops NR from starting. As it can affect a random file, you then have to scan through all the context files looking for the one with zero length, delete it, and restart NR.

  3. stefankapp commented on Nov 27, 2020

    @stefankapp

    Hi, we discover the same issue running NR on Windows. We set to flush the context variables to the local file system. In case the PC is shut down immediately, e.g. due to power loss, at next startup, NR terminates with "Error loading context store".

    Our workaround is to create a backup of the context directory (when needed and when the PC is running properly) and restore this backup on each startup of NR, to ensure NR starts. However, this limits the possible use of storing to disc considerably.

    We would be looking forward to a solution which avoids creating these invalid context files. (We haven't found what could be exactly the problem in the source code of NR)
    Another approach would be to programmatically create a backup of the context folder (like for the flows) and restore this backup if starting NR fails for the abovementioned error. Or, if this doesn't help, start NR with cleared context directory. Not starting at all is a critical issue thinking of automated operation.

    Best regards
    Stefan

    Node-RED version: v1.0.4
    Node.js version: v10.16.3
    npm version:
    Platform/OS: Win10 x64
    Browser:
    running in Docker: no

  4. marcusekeenan commented on Sep 2, 2022

    @marcusekeenan

    Same issue here on Windows. Power loss cause the global context file to be cleared.

  5. Steve-Mcl commented on Sep 4, 2022

    @Steve-Mcl
    Contributor

    Same issue here on Windows. Power loss cause the global context file to be cleared.

    @marcusekeenan this issue is almost 2 years old & many things have changed since node-red v1.0.4

    You will need to detail your node/node-red version, how you have set up persistent storage in your settings file and any other relevant info (like running in docker, or as a home assistant pluggin, running as a service etc etc etc)

  6. DmitrySidorow commented on Jun 26, 2025

    @DmitrySidorow

    today I came across the fact that the file was empty after an unexpected power outage. I will store it in sqlite

  7. knolleary commented on Jun 10, 2026

    @knolleary
    Member

    Closing as part of a tidy-up of the issue tracker — this has been inactive for a long time and much has changed in Node-RED since. If it's still relevant on a current version, please open a fresh issue with up-to-date details and we'll take a look. Thanks for raising it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions