Skip to content

all: Handle errors opening db/creating file-set (ref #5907) - #7150

Merged
calmh merged 12 commits into
syncthing:mainfrom
imsodin:lib/dbErrors
Dec 21, 2020
Merged

calmh merged 12 commits into
syncthing:mainfrom
imsodin:lib/dbErrors

Conversation

@imsodin

@imsodin imsodin commented Nov 24, 2020

Copy link
Copy Markdown
Member

This is a first step towards graceful error handling in the db layer. It introduces error return values to NewLowlevel and NewFileSet. That requires a mechanism in the model to handle fatal errors when starting folders, which is just a one-buffered channel for fatal errors that the model service receives from to initiate shutdown.

This means that errors which were previously panics and thus reported now result in a graceful shutdown, i.e. no panic reporting. Thus I introduced failure reporting in the db. The principle is that every package is responsible for reporting it's own failures, even if that failure results in a returned error. The reasoning is, that only at the error source you can know if the error needs reporting and whether it's actually safe to report (e.g. doesn't contain paths or ids).

Previously such fatal failures would hardly ever get reported, as the reporting service gets torn down due to the fatal failure before it sends them. Now unreported failures are written to disk when the service stops and these failures are then reported on next startup.

@calmh

calmh commented Nov 24, 2020

Copy link
Copy Markdown
Member

zomg

@ProactiveServices

Copy link
Copy Markdown
Contributor

zomg

@imsodin is a beast and nothing can stop him.

@AudriusButkevicius

Copy link
Copy Markdown
Member

The reasoning is, that only at the error source you can know if the error needs reporting and whether it's actually safe to report (e.g. doesn't contain paths or ids).

Why not check if the error satisfies some reportable interface or something?

Having to push down the whole reporting mechanism stack down so deep feels icky.

@imsodin

imsodin commented Nov 26, 2020

Copy link
Copy Markdown
Member Author

Why not check if the error satisfies some reportable interface or something?

Having to push down the whole reporting mechanism stack down so deep feels icky.

There are conditions in the db package where I'd like to generate a report, but that are handled internally. Like metadata counters becoming negative or empty globals. That's stuff that should never happen, but also isn't bad enough to justify making it fatal (or just recoverable).

@calmh calmh left a comment

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.

Good stuff

Comment thread lib/model/model.go Resolved
Comment thread lib/model/model.go Resolved
Comment thread lib/model/model.go Resolved
Comment thread lib/ur/failurereporting.go Resolved
Comment thread lib/model/model.go Outdated
return fatalErr(err)
}

m.cfg.Subscribe(m)

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.

We could miss a config change after initFolders but before we subscribe, so perhaps subscribe before initFolders?

@imsodin imsodin Dec 9, 2020 •

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.

Probably better that way round, yes. However really there should be a hook or something on Subscribe to initialize the subscriber with the config that's in place while subscribing. Otherwise you can still have the race that a config change comes in while we are still initialising folders (which isn't even so unlikely, given creating the filesets and recalculating metadata can take a while).

Edit:
Though such a hook is also problematic, as to be effective it would have to block further config changes while executing the hook, and again that can take a long time and thus blocking a lot of things which causes other badness.

Comment thread lib/model/model.go Resolved
Comment thread lib/model/model.go Resolved

@calmh calmh left a comment •

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.

LGTM, has conflicts

@calmh
calmh merged commit 78bd034 into syncthing:main Dec 21, 2020
calmh added a commit to calmh/syncthing that referenced this pull request Dec 21, 2020
* main: (27 commits)
  lib/fs: Correct wrapping order for meaningful log-caller (syncthing#7209)
  all: Handle errors opening db/creating file-set (ref syncthing#5907) (syncthing#7150)
  cmd/relaypoolsrv: Allow validation of relay join requests by certificate (fixes syncthing#7196) (syncthing#7217)
  lib: Close underlying conn in protocol (fixes syncthing#7165) (syncthing#7212)
  lib/db: Prevent IndexID creation race (syncthing#7211)
  gui: Reflect change in untrusted in sharing tab (syncthing#7201)
  lib/db: Remove index ids when dropping folder (syncthing#7200)
  lib/model: Fix flaky test and add some scanning debug (syncthing#7214)
  lib: Consistently set suture logging (syncthing#7202)
  lib/model: Unflake TestIgnoreDeleteUnignore (syncthing#7208)
  gui: Apply changes to untrusted (ref syncthing#6443) (syncthing#7206)
  lib/config: Remove deprecated pending entries from config (ref syncthing#6443) (syncthing#7204)
  all: Store pending devices and folders in database (fixes syncthing#7178) (syncthing#6443)
  gui, man, authors: Update docs, translations, and contributors
  gui: Sort folders and devices in advanced config modal (syncthing#7192)
  model: Actually print folder description in "Overriding" log message
  gui: version.tags is an array, which is truthy when empty
  build: Switch to gopsutil's v3 module (syncthing#7191)
  build: Update notify (fixes syncthing#7076) (syncthing#7189)
  lib/api: Returns tags in version as list (syncthing#7190)
  ...
@imsodin
imsodin deleted the lib/dbErrors branch December 21, 2020 14:42
@calmh calmh added this to the v1.13.0 milestone Dec 21, 2020
@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 Dec 22, 2021
@syncthing syncthing locked and limited conversation to collaborators Dec 22, 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: nil pointer dereference because (*db.Lowlevel)getMetaAndCheck() returns nil

5 participants