You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a private project that uses go.rice. It works flawlessly on Windows, but on Linux, it fails with:
panic: could not locate box "assets"
It is compiled from the exact same source, on the same host (Windows 10), with the same Go toolchain (1.15). I started debugging go.rice, and noticed a very interesting race condition. I will simplify it below.
Only then will rice-box.go be called, but by that time, the program will have panicked, because the assets box is not loaded. There are many additional ways this issue can be hit, including much less-trivial nested and multi-thread cases like in my private project.
Solution
The root of the problem is that the resource initialization is detached from the resource usage. Other projects such as binclude reference a variable in the generated file instead of global library functions in go-rice's case. You can reduce the amount of race cases in go-rice by making the resource initialize via a const/var instead of init() function, but ideally, a whole different approach should be employed.
The text was updated successfully, but these errors were encountered:
I have a private project that uses go.rice. It works flawlessly on Windows, but on Linux, it fails with:
It is compiled from the exact same source, on the same host (Windows 10), with the same Go toolchain (1.15). I started debugging go.rice, and noticed a very interesting race condition. I will simplify it below.
Intro
Recall the order in which Go initializes code: https://stackoverflow.com/questions/24790175/when-is-the-init-function-run
Say you have the following project:
rice-box.go
main.go
The issue
The first thing that will load is:
Only then will
rice-box.go
be called, but by that time, the program will have panicked, because theassets
box is not loaded. There are many additional ways this issue can be hit, including much less-trivial nested and multi-thread cases like in my private project.Solution
The root of the problem is that the resource initialization is detached from the resource usage. Other projects such as binclude reference a variable in the generated file instead of global library functions in go-rice's case. You can reduce the amount of race cases in go-rice by making the resource initialize via a
const
/var
instead ofinit()
function, but ideally, a whole different approach should be employed.The text was updated successfully, but these errors were encountered: