Skip to content

lib/model, lib/scanner: Prevent races aborting scans (fixes #6994) - #6997

Merged
imsodin merged 4 commits into
syncthing:mainfrom
imsodin:model/snapRaceOnErr
Sep 25, 2020
Merged

imsodin merged 4 commits into
syncthing:mainfrom
imsodin:model/snapRaceOnErr

Conversation

@imsodin

@imsodin imsodin commented Sep 21, 2020 •

Copy link
Copy Markdown
Member

This addresses two races which may lead to the panic reported in #6994:

One when a db error occurs: We immediately return in folder.scanSubDirs, not waiting for the scanner to terminate (close the returned chan).

Another when the scan is cancelled by context: The hasher aborts on context, and if it does so faster than the walker routine, it may close the returned channel while the walker is still working. Now the context is only checked when sending to the returned channel. Sends to "internal channels" are done without consideration of context, such that we can be sure everything is done when closing the returned channel.

I can't actually be sure this fixes #6994, as I can't deduct what exactly is happening from the trace, but the fixed scenarios might cause a panic with such a trace. Thus I believe it's fine to close that issue - we can always reopen if the same panic comes up again afterwards.

@imsodin
imsodin force-pushed the model/snapRaceOnErr branch from 0f8b49b to 6d4a16e Compare September 21, 2020 09:19
@imsodin imsodin changed the title lib/model: Prevent race on db-error while scanning (fixes #6994) lib/model, lib/scanner: Prevent races aborting scans (fixes #6994) Sep 21, 2020
Comment thread lib/scanner/blockqueue.go
defer ph.wg.Done()

for {
select {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why remove the outer select? I guess the intent is that the inbox will be closed, but it looks odd that we only check the context on one "side" of the processing stage?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For one I somehow managed to commit the related changes in walk.go to another branch, making this change nonsensical anyway. My previous logic was to only check context on outbox/finishedChan, which is returned to the caller. That's unnecessary though, the only place we mustn't check context is the counter goroutine to not break the link between filesystem walking and hashing. Then wait on ph.inbox to be closed before closing ph.outbox to be sure filesystem walking finished when the returned channel gets closed.

Comment thread lib/scanner/walk.go Outdated
// We do not abort on context here because the link between the
// filesystem walker and the hasher must not be interrupted, otherwise
// the hasher might close finishedChan (returned to caller) before
// the filesystem walker is done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think that can happen? The walk is done as all files have been added to the filesToHash slice in the loop above on line 152-155. It shouldn't matter whether we send all of them or not

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right - diff getting smaller again.

@imsodin
imsodin merged commit 8452fd2 into syncthing:main Sep 25, 2020
@imsodin
imsodin deleted the model/snapRaceOnErr branch September 25, 2020 09:27
@calmh calmh added this to the v1.10.1 milestone Sep 28, 2020
calmh added a commit to calmh/syncthing that referenced this pull request Sep 29, 2020
* main:
  lib/fs: Add COM0 and LPT0 to invalid Windows file names (ref syncthing#7008) (syncthing#7013)
  lib/fs: Be even more strict about Windows names (ref syncthing#7008) (syncthing#7012)
  lib/fs: Be more clear about invalid file names (ref syncthing#7010) (syncthing#7011)
  lib/model: Disallow reserved names, and names ending with period on Windows (fixes syncthing#7008) (syncthing#7010)
  lib/model, lib/scanner: Prevent races aborting scans (fixes syncthing#6994) (syncthing#6997)
  lib/fs: Use file clone ioctl wrappers and types from golang.org/x/sys/unix (syncthing#7000)
  Update config.yml
  gui, man, authors: Update docs, translations, and contributors
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Sep 26, 2021
@syncthing syncthing locked and limited conversation to collaborators Sep 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"panic: filling Blocks: leveldb: snapshot released" on folder save

3 participants