-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove panics in the library code #447
Comments
I fix this. |
I don't agree with this statement in this specific context:
Looking at the error list above... most mean that the underlying bbolt file is corrupted or inconsistent. Moreover panic in golang is not 'terminal'. If the user of the library is determined to continue (e.g. because of hosting multiple instances in a single process), the panic can get explicitly recovered. To summarise, I recommend:
|
I try this in infdahai@7d07d9f. And I agree with @ptabor said. We can replace some panics with error messages, such as |
"page %d already freed" is also indicator of either bug in freelist implementation or memory stomping or ram/cpu corruption. It shouldn't happen regardless of bbolt lib user actions. |
I definitely agree on this. However, I think this should not be the default behavior. Think about these 2 cases:
Panicking takes the whole program down which is not an ideal decision for a library in my opinion. I propose this:
There is also a special case. Recover only works when called from the same goroutine as the panic is called in. For example: Lines 1178 to 1182 in 56e033b
This code block executes when opening a db and it's not possible to recover that panic. In overall, I see corruption errors as non-fatal. I think it's nicer to let the user decide by returning regular errors. |
A library should not panic at all. Panics are usually not handled in Go programs and it makes the whole program crashes when a library function panics.
Currently there are 12 open issues involving panic, especially working with corrupted databases. BoltDB should return the error as an nice message.
Overview of panics from boltdb code:
The text was updated successfully, but these errors were encountered: