wakatime/visualstudio-wakatime

Locking file randomly

rolivares opened this issue · 8 comments

Seem to the extension using VS and starting VS as ADMIN randomly is locking files. So, suddenly changes maded into files could'n been saved because some process is locking the file asking to save into alternative path.

Using Handle (https://learn.microsoft.com/en-us/sysinternals/downloads/handle) I've found wakatime is locking the file.

Sadly, I can not write some stepts in order to repeat the lock, because seems to be randlomly or unknoun behavior.

The file being locked is one opened by you inside Visual Studio? The plugin does read your opened files using wakatime-cli for things like total file length, and language detection. Maybe there's a way to read files without causing Windows to lock the file.

Here's a related thread pointing to Go standard library code showing os.Open uses non-exclusive mode:

os.Openos.OpenFilesyscall.openFileNologsyscall.Open

However, it does prevent the file from being renamed or deleted. We can write our own syscall.Open to bypass that, but it should already allow writing files while wakatime-cli is reading them.

@rolivares we just updated wakatime-cli. Can you restart your IDE and see if it's fixed?

Test over 16:40 hrs on ClienteService.cs
26.000 lines of code aprox into the file
1MB size for this file

Still blocking file .... It could be because the file size/length that init some not awaited response? On other files with "normal" size apparently it is not blocking ...

image
wakatime.log

From your wakatime.log, you got the fixed version starting 2024-01-18T16:26:02-03:00. Did the locking error happen after that time or only brefore?

after and before , The fix didn't seems to work for this issue

It only happens on files larger than 1MB? And it never happens with WakaTime disabled?

I've looked through the extension source code and WakaTime.Shared.ExtensionUtils source code to verify no extension code is opening or reading the currently focused file. It only uses the path as string, passing that to wakatime-cli.

If we can reproduce this, for example if it always happens using large files, then I'll re-open the issue.