Repository navigation
lib/model, lib/scanner: Prevent races aborting scans (fixes #6994) - #6997
Conversation
0f8b49b to
6d4a16e
Compare
| defer ph.wg.Done() | ||
|
|
||
| for { | ||
| select { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| // 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Right - diff getting smaller again.
* 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
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.