WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Wsl2 sometime corrupt .zsh_history and git

Open lrnzfrr opened this issue 6 years ago • 34 comments

Wsl2 often corrupt .zsh_history file. Other times corrupt git rep ( i use git in wsl, not win version ).

wsl distro: Ubuntu 18.04 wsl version: 2 windows ver: 10.0.19041.172

lrnzfrr avatar Mar 28 '20 20:03 lrnzfrr

I also had file corruption problems with Windows 10 but not only on WSL.

In my case it was the Fast Startup feature. I was dual booting with another Windows 10 Insider build and it was a mess every time I tried to boot the other Windows. Since I disabled that feature I had no problems with file corruption.

onomatopellan avatar Apr 04 '20 11:04 onomatopellan

Same here. Corrupt .zsh_history and .git

WSL DIstro: Ubuntu 20.04 WSL Version: 2 Windows Version: 10.0.19041

GSPATalinjug avatar Jun 01 '20 02:06 GSPATalinjug

Same here, corruption appears randomly after reboots or sleep wake-ups.

WSL Distro: Ubuntu 20.04 WSL Version: 2 Windows Version: 10.0.19041.330 Insider's preview (Slow Ring)

I have a dual boot setup so fast startup is already disabled on my system.

Edit: eventually I've started to wsl --shutdown manually after each session to minimize corruption

luigimannoni avatar Jun 23 '20 12:06 luigimannoni

i just got this corrupt git repo issue, happened twice in a span of a week. i dual boot win 10 and manjaro, wsl2 distro is ubuntu 20.04, and files are in wsl file system

antonmaju avatar Jun 26 '20 01:06 antonmaju

This happens to me about once per month in WSL2. Corrupts ~/.zsh_history (adds some garbage characters to the file) as well as corrupting files in my the .git directory of the project I'm working on.

Fast Startup feature is disabled.

markprzepiora avatar Aug 12 '20 23:08 markprzepiora

I have the "blessing" of getting this history file corruption on each and every reboot, possibly because I run a wsl job on startup and a window is kept open. Based on @anaisbetts's comment re the VM power being turned off impolitely, I tried to add a task when windows shuts down based on this page, with the action being wsl.exe --shutdown, and trying a few reboots I didn't get the corruption.

Not enough data to make this more than a personal anecdote, but maybe others will try it too...

elibarzilay avatar Oct 02 '20 20:10 elibarzilay

I sometimes get this on reboots. when i open .zsh_history i visually search for garbage and delete the particular line which tends to be located near the end.

This can also happen when force restarting WSL2, in case networking stops working with:

Restart-Service -Force -Name hns
Restart-Service LxssManager

squeaky-pl avatar Oct 05 '20 08:10 squeaky-pl

@elibarzilay I did create this script to run wsl.exe --shutdown too and seems the problems have ceased.

For anyone who wants to try it too to stop corrupting history and git:

  1. Create a Basic Task in Task Scheduler
  2. Name it WSL Shutdown
  3. Set the options when a specific event is triggered:
Type : On Event (Basic)
Log : System
Source : User32
EventID : 1074
  1. Set action as initiate a program/script
  2. Set wsl.exe --shutdown and confirm

I'm using WSL Distro: Ubuntu 20.04 WSL Version: 2 Windows Version: 10 20H2

marceloavf avatar Oct 26 '20 10:10 marceloavf

One warning though: at least in one case I had lost a file that was open in a windows app (via wsl$) which tried to save it after shutdown started, and it ended up with a corrupt (all NULs) file. (I think that it happened because I canceled the reboot, then saved the file, then rebooted -- and I'm guessing that the shutdown happened on the first reboot starting.)

elibarzilay avatar Oct 26 '20 21:10 elibarzilay

I've added a task in the scheduler like @marceloavf suggested, however I just got another repository corrupted on the last shutdown.

Manually shutting down with wsl.exe --shutdown before shutting down seems to be still the more reliable method

luigimannoni avatar Nov 03 '20 22:11 luigimannoni

I'm also encountering this issue. Both .zsh_history and project git files are being corrupted. It appears to happen somewhat randomly to me...

  • WSL Distro: Ubuntu 20.04
  • WSL Version: 2
  • Windows OS Build: 19042.630
  • Fastboot is disabled.
  • Primarily using the Windows Terminal app and sometimes using the integrated terminal in VSCode.

Empereol avatar Nov 16 '20 14:11 Empereol

image WSL corrupts my git repo every week.

  • Distro: Ubuntu 20.04
  • WSL2
  • Windows 20H2 (Build -10.0.19042.630)
  • Using Windows Terminal by Microsoft.

ridays2001 avatar Nov 17 '20 12:11 ridays2001

Same here. Need to start testing the shutdown method. What are your methods to revert .git? right now I just clone the repo again and move all my changes there, so I don't lose my changes at least.

MartinMuzatko avatar Dec 28 '20 14:12 MartinMuzatko

I use this:

rm -rf .git &&                    # delete old corrupted repo
git init &&                       # initialise new repo
git remote add origin "${url}" && # link to old repo
git fetch &&                      # get old history
git reset origin/master --mixed   # force update to old history

ridays2001 avatar Dec 28 '20 16:12 ridays2001

@therealkenc, not sure if you are the best person to ping, but I've seen you add the "bug" tag to other issues in this repo. It would nice if this issue could be triaged and acknowledged as a bug, since it seems to affect a bunch of people (25 likes in this issue, plues other open related issues like https://github.com/microsoft/WSL2-Linux-Kernel/issues/168 or https://github.com/microsoft/WSL/issues/5895). Right now I have the feeling nobody is looking at this, and I can confirm not only that it happens quite often, but also that it is a very annoying bug from a user perspective. From what I gather in the different issues, it seems to be related to how the WSL subsystem gets shut down.

Is there anything I can do to get this issue triaged?

edrevo avatar Dec 30 '20 21:12 edrevo

This happened to me today. My local git repo got corrupted. Thankfully I had no pending commits.

TheFirstMe avatar Jan 01 '21 08:01 TheFirstMe

I use this:

rm -rf .git &&                    # delete old corrupted repo
git init &&                       # initialise new repo
git remote add origin "${url}" && # link to old repo
git fetch &&                      # get old history
git reset origin/master --mixed   # force update to old history

I have two active branches: master and dev. What would the approach be then?

TheFirstMe avatar Jan 01 '21 08:01 TheFirstMe

This happened to me today on a Windows 10 Pro, version 20H2, build 19042.685. I have a different laptop with Windows 10 Home Single Language, version 2004, build 19041.685 and this issue does not occur.

bleepster avatar Jan 03 '21 06:01 bleepster

I use this:

rm -rf .git &&                    # delete old corrupted repo
git init &&                       # initialise new repo
git remote add origin "${url}" && # link to old repo
git fetch &&                      # get old history
git reset origin/master --mixed   # force update to old history

I have two active branches: master and dev. What would the approach be then?

I have found the following to be effective

find .git/objects/ -size 0 -exec rm -f {} \;

No need to resync the whole repo

luastoned avatar Jan 04 '21 11:01 luastoned

Seems like MSFT is finally looking into this issue! ♥ https://github.com/microsoft/WSL2-Linux-Kernel/issues/168#issuecomment-754106399

edrevo avatar Jan 04 '21 18:01 edrevo