Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fix of not picking file modifications. #12353

Merged
merged 4 commits into from
May 4, 2016

Conversation

mfatekho
Copy link
Contributor

@mfatekho mfatekho commented Apr 8, 2016

Inapproriate use of win api in fs_even_node module. In fsevents_win.cpp there are a thread that monitors file system events queue and post messages to uv library. Proposed solution is to use extra bool variable in THREADINFO structure to control thread exit state
@busykai

Inapproriate use of win api in fs_even_node module. In fsevents_win.cpp there are a thread that monitors file system events queue and post messages to uv library. Proposed solution is to use extra bool variable in THREADINFO structure to control thread exit state
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014 - present Adobe Systems Incorporated. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change, the base of your commit, seems to be a left-over of the intermediate work. Could you please rebase the commit on top of adobe/master?

EDIT: this is an incorrect comment, my bad.

@busykai
Copy link
Contributor

busykai commented Apr 11, 2016

@peterflynn, @bchintx, @abose: we were able to reproduce the filewatchers going offline. we expect this is supposed to fix #7638 and related issues. The issue occurs when some other tools interferes with the same file(s) causing "spurious" messages which result in this condition resolves to FALSE and causes the filewatchers to quit abruptly.

The fix consists of keeping an internal flag of whether the filewatchers should quit instead of relying on specific parameters of the "terminate" message.

@@ -337,7 +339,7 @@ DWORD WINAPI NodeFSEvents::Run(LPVOID lpData)
{
// iterate watching for directory changes until we're signalled to stop
BOOL bContinue = TRUE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable should be taken off entirely. Since you removed the code at lines 386-390, bContinue never changes the value and having it around is excessive and not needed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to changes now bContinue reflects status from winapi call at line 346 ReadDirectoryChangesW, in some situations that function may fail and return false according to MSDN, that leads to looper exit. Do you propose to skip error handling for that function and continue watching thread as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I simply missed that line. You're right, the logic's good.

Copy link
Contributor

@bchintx bchintx Apr 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfatekho I think there's still a logic error here. If the ReadDirectoryChangesW() call below fails, then bContinue is assigned the value of FALSE. As a result, on the next iteration of the loop, the while condition below in line 342 will still be false, and we'll still get kicked out of the loop.

I'd partially agree with @busykai 's comment above, and propose removing bContinue from the while loop condition expression in line 342. In fact, you might as well get rid of bContinue variable altogether and just move the ReadDirectoryChangesW() call inside the if condition in line 351.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bchintx there are several points with removing bContinue and leaving the rest untouched.

  1. on line 247 there are FILE_FLAG_OVERLAPPED is set meaning ReadDirectoryChangesSW is working in async mode.
  2. MSDN says that for asynchronous mode returning value is a result of task submission, false means we run out of some resources, handles, stack, ram, etc.
  3. Submitting new requests, e.g. calling ReadDirectoryChangesSW in that situation (if that ever happen i believe in low resource condition there will be lots of problems) makes situation even worse: I'm not sure whether that function will issue SwitchToThread call, if not we will have one cpu core load spot until low resource condition go away.
  4. Further reading of possible error codes reported by ReadDirectoryChangesW() makes me think they all are not recoverable, so no point to keep that loop

I just wanted to say that if we simply ignore that error we have to think about possible short loop that burns CPU, and at least add SwitchToThread(), Sleep(0), etc, if we decided to not abort watcher thread.

Copy link
Contributor

@busykai busykai Apr 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just get rid of bContinue it bothers me (both its name and its use in the while condition). Just like @bchintx pointed out, let's wrap the ReadDirectory... call in an if, this way @evgen48's concern of not handling the error condition will be addressed too.

@busykai
Copy link
Contributor

busykai commented Apr 13, 2016

LGTM. Will merge soon after the copyright is fixed.

@swmitra
Copy link
Collaborator

swmitra commented Apr 14, 2016

LGTM 👍

@MiguelCastillo
Copy link
Contributor

This looks good to me. Totally got PTSD from old C++ days... :D

@ingorichter
Copy link
Contributor

Looks like a simple fix to get rid of the problem.

@bchintx
Copy link
Contributor

bchintx commented Apr 14, 2016

Please don't merge quite yet. Please see my comment inline above, as I think there's still a logic error that will prevent the fix from working as expected.

@ingorichter
Copy link
Contributor

@bchintx I was thinking about getting rid of bContinue, but you said it way better than I could have done this. ;-)

@mfatekho
Copy link
Contributor Author

Hi guys,
Refactored code a little due to your recommendations. As you suggested, I have removed bContinue variable and wrapped ReadDirectoryChangesW to if.

{
&dwBytesReturned, lpThreadInfo->m_lpOverlapped, NULL)) {
break;
}
// wait for a signal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 351-358 can be indented left now.

@ingorichter
Copy link
Contributor

Poking @bchintx to have another look.

@bchintx
Copy link
Contributor

bchintx commented May 4, 2016

Looks good to me. Merging!

Nice work @mfatekho!

@bchintx bchintx merged commit a78983d into adobe:master May 4, 2016
@busykai
Copy link
Contributor

busykai commented May 5, 2016

Yay! Thanks @mfatekho and @evgen48 for root-causing and fixing this!

@MegaArman
Copy link

MegaArman commented Sep 23, 2020

Just trying out brackets for the first time today. Here's my trouble scenario:
-have some files open
-git checkout in my terminal
-the files are not reloaded automatically nor am I prompted to reload them
-Write some code
-Hit ctrl-s and now I am given a dialogue window if I want to overwrite what's on disc. This is an issue because now I have to figure out if my changes to the file are actually OK

In the Geany editor under Edit->Preferences->Files-> Disc check timeout, you can set how often the disk is checked and it will prompt you to reload the file if changes are detected

Is there something like that for Brackets?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants