numtide / treefmt

one CLI to format your repo [maintainers=@zimbatm,@brianmcgee]
https://treefmt.com
MIT License
620 stars 38 forks source link

Question: Should treefmt specify a timeout when trying to open its boltdb cache? #408

Closed jfly closed 2 months ago

jfly commented 2 months ago

While debugging https://github.com/numtide/treefmt/issues/406, I found that if you have one treefmt process hung, the next treefmt process you start up will get hung on this call to bolt.Open. This behavior is documented by bbolt:

Please note that Bolt obtains a file lock on the data file so multiple processes cannot open the same database at the same time. Opening an already open Bolt database will cause it to hang until the other process closes it. To prevent an indefinite wait you can pass a timeout option to the Open() function:

db, err := bolt.Open("my.db", 0600, &bolt.Options{Timeout: 1 * time.Second})

Should treefmt specify a timeout here? Ideally treefmt would never hang, but it feels especially unfortunate that if it does hang, it'll cause other treefmt processes to hang.

brianmcgee commented 2 months ago

Completely agree #409

jfly commented 2 months ago

Closing, as @brianmcgee added a timeout in https://github.com/numtide/treefmt/pull/409. Thanks!