Commit 25e04bd9 authored by David Vorick's avatar David Vorick

panic on overlapping files

Don't print the stack during Critical for tests. Don't print the github issues
string either.
parent e328dc0d
......@@ -12,8 +12,10 @@ import (
// the running goroutine is printed to help determine the error.
func Critical(v ...interface{}) {
s := "Critical error: " + fmt.Sprintln(v...) + "Please submit a bug report here: https://github.com/NebulousLabs/Sia/issues\n"
debug.PrintStack()
os.Stderr.WriteString(s)
if Release != "testing" {
debug.PrintStack()
os.Stderr.WriteString(s)
}
if DEBUG {
panic(s)
}
......@@ -26,8 +28,10 @@ func Critical(v ...interface{}) {
// integrity.
func Severe(v ...interface{}) {
s := "Severe error: " + fmt.Sprintln(v...)
debug.PrintStack()
os.Stderr.WriteString(s)
if Release != "testing" {
debug.PrintStack()
os.Stderr.WriteString(s)
}
if DEBUG {
panic(s)
}
......
......@@ -95,6 +95,7 @@ func LoadJSON(meta Metadata, object interface{}, filename string) error {
_, exists := activeFiles[filename]
if exists {
build.Critical(ErrFileInUse, filename)
return ErrFileInUse
}
activeFiles[filename] = struct{}{}
......@@ -145,6 +146,7 @@ func SaveJSON(meta Metadata, object interface{}, filename string) error {
_, exists := activeFiles[filename]
if exists {
build.Critical(ErrFileInUse, filename)
return ErrFileInUse
}
activeFiles[filename] = struct{}{}
......
......@@ -72,19 +72,25 @@ func TestSaveLoadJSON(t *testing.T) {
// Try saving the object multiple times concurrently.
var wg sync.WaitGroup
errs := make([]error, 250)
errs := make([]bool, 250)
for i := 0; i < 250; i++ {
wg.Add(1)
go func(i int) {
errs[i] = SaveJSON(testMeta, obj1, obj1Filename)
wg.Done()
defer wg.Done()
defer func() {
r := recover() // Error is irrelevant, managed by err slice.
if r != nil {
errs[i] = true
}
}()
SaveJSON(testMeta, obj1, obj1Filename)
}(i)
}
wg.Wait()
// At least one of the saves should have complained about concurrent usage.
var found bool
for i := range errs {
if errs[i] == ErrFileInUse {
if errs[i] {
found = true
break
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment