New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firestore emulator sometimes fails on data export when stopped #3092
Comments
@yuchenshi - Can you take a look at this? |
Hi @madmacc, thanks for the report. Would you mind expanding a bit about the steps you're taking before seeing this issue? For example, how much data is being saved? What SDKs are you using? Are you using any of the other emulators in conjunction with Firestore? |
Sure @samhorlbeck. I am using v9.2.1 of the firebase-tools. Let me know if you need any more information. |
What is your general use case? Can you discern any particular action that reliably causes the data to not be saved correctly? Basically I'm just trying to get a sense of how we could start to debug this issue and potentially reproduce it. |
Unfortunately not. I'm sure there is some reason but it seems random to me at this stage. At the moment when it is successful I manually copy the exported data to a safe location so it is not deleted. I was hoping the logs would show something but they don't unless I am looking in the wrong place. Root of the project firestore-debug.log. I am just testing an web application locally using the firebase js sdk and angularfire. |
I just tried starting and stopping it about 10 times in a row and it worked every time. So not sure what it is but it is either time related or caused by something else. |
I just had a similar issue after leaving my computer for a couple of hours in sleep mode. Log is attached. Looks the same. I'm not sure if this is correct log file as it doesn't have much interesting in it.
|
The Emulator Suite writes a temporary file to keep track of the running instances, and looks like that file was deleted somehow before you terminated the suite. For example, Windows may delete those temporary files to reclaim disk space (especially if disk space is low), or it may be some other cleanup tools installed on your dev machine. Right now, |
@yuchenshi Ok that 2nd error above is because I am running two instances of the emulator. If I stop the functions emulator first it causes that problem. This is not the problem where it deletes the exported data files, it just fails to export. Unfortunately it doesn't resolved my original problem of it deleting the files though. |
Glad we found that out! The export APIs cannot handle two instances running together yet, but the internal bug I've created above should be able to solve this. In the meantime, have you considered creating symlinks so that your functions can be "part of" the main project directory? They are available on Windows 10 and you can ignore them in |
This is a good idea. I have not used them before but have had them on my todo list, I will give it a try. I tried a shortcut which of course did not work! It must be common scenario for people that have multiple apps in their firebase project. Not sure why I am the only one who has brought it up. |
Actually after some more testing the first issue with the deleted export data files is due to the two instances of the emulator running. UPDATE: If anyone else want to do this the command on Windows is: |
Am seeing this also on Mac, every other time my export files are either corrupted or missing data. Will comeback with the detail |
On macOS 11.1 with On WebStorm 2020.3.2 when using the "Run" button on // package.json
"emulators:start": "firebase emulators:start --project=\"local-emulators\" --import=\"./a\" --export-on-exit=\"./a\"" The result is: /Users/carlos.chida/.nvm/versions/node/v12.13.0/bin/node /usr/local/Cellar/yarn/1.22.5/libexec/bin/yarn.js run emulators:start
yarn run v1.22.10
$ firebase emulators:start --project="local-emulators" --import="./a" --export-on-exit="./a"
...
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://localhost:4000 │
└─────────────────────────────────────────────────────────────┘
### STOPPED THE PROCESS VIA WEBSTORM ###
i emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown.
i emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now.
i Automatically exporting data using --export-on-exit "./a" please wait for the export to finish...
⚠ Emulator UI has exited upon receiving signal: SIGINT
i Found running emulator hub for project local-emulators at http://localhost:4400
i Creating export directory /Users/carlos.chida/WebstormProjects/veriphi/functions/a
i Exporting data to: /Users/carlos.chida/WebstormProjects/veriphi/functions/a But only the folder gets created without any contents. I'm assuming that WebStorm is not giving the process enough time after sending the interrupt signal. On the other hand, when running yarn emulators:start
yarn run v1.22.10
$ firebase emulators:start --project="local-emulators" --import="./a" --export-on-exit="./a"
...
### PRESSED ctrl-C
i emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown.
i emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now.
i Automatically exporting data using --export-on-exit "./import-export-data" please wait for the export to finish...
i Found running emulator hub for project local-emulators at http://localhost:4400
i Creating export directory /Users/carlos.chida/WebstormProjects/veriphi/functions/import-export-data
i Exporting data to: /Users/carlos.chida/WebstormProjects/veriphi/functions/import-export-data
i emulators: Received export request. Exporting data to /Users/carlos.chida/WebstormProjects/veriphi/functions/import-export-data.
$ ### NEW PROMPT!
➜ ✔ emulators: Export complete.
✔ Export complete
i emulators: Shutting down emulators.
i ui: Stopping Emulator UI
⚠ Emulator UI has exited upon receiving signal: SIGINT
i functions: Stopping Functions Emulator
i database: Stopping Database Emulator
i firestore: Stopping Firestore Emulator
i pubsub: Stopping Pub/Sub Emulator
⚠ functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
i auth: Stopping Authentication Emulator
i hub: Stopping emulator hub
$ ### ANOTHER NEW PROMPT |
@carloschida Thanks for the report! Exporting may take a few seconds and if WebStorm isn't giving the emulator enough time to do the work, there isn't a ton we can do here. We suggest running |
Indeed. We plan on fixing this in our project by moving of Firestore. |
I opened a new issue here with multiple bugs also including this one. #5404 |
Based on my experimentation, it looks like Vite dev server holds a lock on folders that contain sub-folders (at least on Windows). Filed bug report vitejs/vite#11938 |
@sugoidesune a temporary workaround is to change save path to somewhere on |
Did you manage to do relative paths. |
in linux would that work? |
If, like me, your symptoms are caused by the Vite dev server holding locks on nested folders (which can prevent the emulator from renaming its snapshots on Windows), the workaround I'm using is to set |
This worked for me. Thanks! |
Creating a VHD and using it as the export folder worked for me. No matter what I tried, nothing worked when I only had 1 disk drive partition. |
The export always succeeds if I launch the emulator a few minutes/hours ago. But if I leave the emulator running for an extensive time (maybe 1-2 days) on my Mac, the export fails always. Hope this can get fixed. I just lost data again today since I forgot about this issue. |
It is happening no matter what (MacOS). For me this feature never worked. I have this exact problem since I first started experimenting with Firebase years ago. I had this problem on Windows, Mac and with every framework. Even if I just run a static SPA through the hosting emulator (no active dev server). Compiling the comments so far it looks like it is firebase-tools own file change detection mechanism that is locking things up... |
Running
|
SKempin, the emulators create the export in a temp directory and then copy them over once completed: firebase-tools/src/emulator/hubExport.ts Line 134 in 40dd38f
The mkdtemp creation is failing for some reason, inside of /tmp See: https://www.geeksforgeeks.org/node-js-fs-mkdtempsync-method/ Are you running this inside a container or with permissions that would prevent the firebase CLI from creating a temp directory in /tmp? |
@christhompsongoogle thanks, no not running in a container and have also tried running with |
Thanks, This worked also for me. |
No comments since october 2023, am I missing something? This problem is major for the developer experience. For me, changing the path to |
Still not working for me. Does anyone have a different workaround? |
@yanir21 I am running this npm script now to run the emulator and it is successfully exporting on every stop, as long as I stop using
I have a |
@SKempin Still no luck: ...
i Exporting data to: C:\Users\USER\Desktop\functions\emulator_data
i emulators: Received export request. Exporting data to C:\Users\USER\Desktop\functions\emulator_data.
! emulators: Export failed: EPERM: operation not permitted, rename 'firebase-export-1707209884206CzcLW7' -> 'C:\Users\USER\Desktop\functions\emulator_data'
! Export request failed, see emulator logs for more information.
! Automatic export to "emulator_data" failed, going to exit now...
i emulators: Shutting down emulators.
... |
@yanir21 can you push a repo for me to try this? |
Hello, in my case it fails exactly as described by Mainul Islam Farshid,
but I found out that my "running server" process was holding the lock of
the whole directory. In someone's case there could be even others holding
the lock.
So what I have been doing until firebase team solves this:
1 - Before starting the emulator, I check if last export succeeded, if not,
I manually rename the failed exported directory to "firebase-export-data"
2 - Start emulator making sure the export name matches the import argument
when starting emulator: eg: " --import firebase-export-data"
firebase emulators:start --import ./firebase-export-data --export-on-exit
./firebase-export-data --inspect-functions
3 - Work
4 - Before exiting, I stop serving, compiling, and everything else that may
be holding the lock *before *I exit the emulator.
5 - Making sure the emulator is the last running process, I kill it with *one
single* ctrl+c, and wait for it to export (can take a few seconds, so don't
hit several ctrl+C).
6 - I check the directory, if I still have my "firebase-export-data"
folder, if it fails it will change to something like:
"firebase-export-1707209884206CzcLW7".
In this case I manually rename it to "firebase-export-data", to make sure I
don't forget next time I will start the emulator (step 1).
Needs a bit of extra attention, but works for me.
…On Tue, Feb 6, 2024 at 7:34 AM Stephen Kempin ***@***.***> wrote:
@yanir21 <https://github.com/yanir21> can you push a repo for me to try
this?
—
Reply to this email directly, view it on GitHub
<#3092 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQKYLEXTLMCUJKNUGMVKO73YSIBMHAVCNFSM4WX2OA6KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJSHEZDEMZXG43A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I finally managed to solve this 🎉 The root directory (e.g Running So changing the "serve": "npm run build && cd .. && firebase emulators:start --import ./emulator-data --export-on-exit ./emulator-data --inspect-functions" solved it for me. |
@yanir21 solution worked for me too, thanks! |
Our issue was relying on The issue is twofold;
This has the side-effect of import / export not gracefully exporting and explains why different solutions such as disabling I hope this can help you all! |
Still having an error during export:
Even trying to manually rename the specified folder failed with the error, that the contents of the directory are still in use by some program. This error happens on Windows as well as on WSL. |
This worked. |
Describe your environment:
Problem:
When I stop my local firestore emulator most of the time it exports the data fine. However sometimes is has an error and it deletes my export files so I lose all my data. Nothing seems to appear in the logs.
I am using:
firebase emulators:start --import=emulator/emulator-export-data --export-on-exit=emulator/emulator-export-data
Then:
Ctrl+C
to stop the emulator.
I get the following in the terminal:
There is not much in the firestore-debug.log in the root:
The text was updated successfully, but these errors were encountered: