Skip to content

lib: Return error from db.FileSet.Snapshot (fixes #7419, ref #5907) - #7424

Merged
imsodin merged 3 commits into
syncthing:mainfrom
imsodin:lib/snapshotErr
Mar 7, 2021
Merged

imsodin merged 3 commits into
syncthing:mainfrom
imsodin:lib/snapshotErr

Conversation

@imsodin

@imsodin imsodin commented Mar 3, 2021 •

Copy link
Copy Markdown
Member

Purpose

Another step towards better database error handling (#5907), fixing #7419: Now db.FileSet.Snapshot returns an error instead of panicking.
Most of the diff is boilerplate of adding error returns all over the place. One larger change regards folder error handling: Previously we did not bubble errors consistently (as in already existing errors unrelated to this PR). Now we do need errors in Serve to shut the service down in case of fatal errors. I thus opted to bubble "folder-level" errors (as opposed to item level errors, e.g. errors scanning/pulling an item) up to the main loop in the service. That means the folder state is set with any error that reaches that point and isn't fatal.

Testing

Existing unit tests pass and the UI still comes up - haven't done any manual testing beyond that.

@imsodin imsodin changed the title lib: Return error from db.FileSet.Snapshot (ref #5907) lib: Return error from db.FileSet.Snapshot (fixes #7419, ref #5907) Mar 3, 2021
Comment thread lib/model/folder.go Outdated
if !f.pull() && f.pullPause < 60*f.pullBasePause() {
var success bool
success, err = f.pull()
if err == nil && success && f.pullPause < 60*f.pullBasePause() {

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.

This inverts the condition on success -- we shouldn't back off when pull was successfull

Comment thread lib/model/folder_sendrecv.go Resolved
Comment thread lib/model/model.go Resolved
Comment thread lib/model/model.go Outdated
return m.availabilityWithInfo(cfg, snap, file, block), nil
}

func (m *model) availabilityWithInfo(cfg config.FolderConfiguration, snap *db.Snapshot, file protocol.FileInfo, block protocol.BlockInfo) []Availability {

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.

...WithSnapshot seems more specific (or maybe even InSnapshot), or is there some other info we're looking for here?

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.

The unspecific "info" qualifier refers to already having the folder config and snapshot instead of needing to get them from the model, and WithConfigAndSnapshot is a mouthful.

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.

Well... I'd still go with something like snapshotAvailability and skip mentioning the config, at least it says more that it acts on a point in time than just "with info" which is sort of saying nothing. :)

Comment thread lib/model/folder.go
if success {
return true
if success && err != nil {
return true, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be success && err == nil?

Comment thread lib/model/folder.go
if err := f.ioLimiter.takeWithContext(f.ctx, 1); err != nil {
f.setError(err)
return true
return true, err

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is the only instance of true + non-nil error being returned. Isn't it easier to drop the bool return value and check for timeout/context canceled in the retrying logic?

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.

Also in the end: A pull can result in no success (files couldn't be synced) without an error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh right, in line 226. Too bad.

@imsodin
imsodin merged commit 310fba4 into syncthing:main Mar 7, 2021
@imsodin
imsodin deleted the lib/snapshotErr branch March 7, 2021 12:43
@st-release st-release added this to the v1.15.0 milestone Mar 9, 2021
calmh added a commit to calmh/syncthing that referenced this pull request Mar 11, 2021
* main:
  build: Update notify (syncthing#7444)
  next-gen-gui: Add button to restore default theme (syncthing#7433)
  lib/protocol: Optimize FileKey (syncthing#7440)
  cmd/syncthing, etc: Consistent failure restart backoff (syncthing#7439)
  lib: Return error from db.FileSet.Snapshot (fixes syncthing#7419, ref syncthing#5907) (syncthing#7424)
imsodin added a commit to imsodin/syncthing that referenced this pull request Mar 12, 2021
@calmh calmh added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Aug 11, 2022
@syncthing syncthing locked and limited conversation to collaborators Aug 11, 2022
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.

4 participants