Skip to content
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

[BUG] Shrink crash on windows #119

Closed
idosavion opened this issue Aug 26, 2024 · 1 comment
Closed

[BUG] Shrink crash on windows #119

idosavion opened this issue Aug 26, 2024 · 1 comment

Comments

@idosavion
Copy link

idosavion commented Aug 26, 2024

I recently encountered a bug where buntdb would crush during shrinking on windows both with latest and 1.2.10, (managed to reproduce consistently, ran on Mac successfully), using the following program:

package main

import (
	"fmt"
	"log"
	"strconv"
	"time"

	"github.com/tidwall/buntdb"
)

func main() {
	db, err := buntdb.Open("data.db")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	err = db.Update(func(tx *buntdb.Tx) error {
		for i := 0; i < 100000; i++ {
			key := "key" + strconv.Itoa(i)
			value := "value" + strconv.Itoa(i)
			err := tx.Set(key, value, nil)
			if err != nil {
				return err
			}
		}
		return nil
	})

	if err != nil {
		log.Fatal(err)
	}}

and encountered the following stack trace:

goroutine 114 [running]:
github.com/tidwall/buntdb.panicErr(...)
/Users/runner/go/pkg/mod/github.com/tidwall/[email protected]/buntdb.go:771
github.com/tidwall/buntdb.(*DB).Shrink.func4(.., {.., 0x4f}, ..?, ., {0xc.., 0x53})
/Users/runner/go/pkg/mod/github.com/tidwall/[email protected]/buntdb.go:755 +0x565
github.com/tidwall/buntdb.(*DB).Shrink(0xc..)
/Users/runner/go/pkg/mod/github.com/tidwall/[email protected]/buntdb.go:767 +0x330
github.com/tidwall/buntdb.(*DB).backgroundManager(0x..0)
/Users/runner/go/pkg/mod/github.com/tidwall/[email protected]/buntdb.go:622 +0x21d
created by github.com/tidwall/buntdb.Open in goroutine 108
/Users/runner/go/pkg/mod/github.com/tidwall/[email protected]/buntdb.go:170 +0x3f9	{"pid": 19376}

(basically, moving the file on windows returned panic: buntdb: rename mydb.db.tmp mydb.db: Access is denied and the original file still exists)

Is there any workaround I should apply in such cases? Should I manage shrinking ourselves?
Thank!

@tidwall
Copy link
Owner

tidwall commented Oct 5, 2024

Closing. I think this was fixed by #120

@tidwall tidwall closed this as completed Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@tidwall @idosavion and others