Changes to linux_reload_workaround to allow calling is_hot_reload_enabled before enable_hot_reload#1040
Changes to linux_reload_workaround to allow calling is_hot_reload_enabled before enable_hot_reload#1040KevinThierauf wants to merge 11 commits intogodot-rust:masterfrom KevinThierauf:linux_reload_workaround-changes
Conversation
|
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1040 |
|
i dont like changing this to allow modifying this setting after it has been set. it seems much safer to me to treat all thread locals one way or another, and not potentially have some be treated one way and others another. maybe the issue is here: gdext/godot-core/src/init/mod.rs Line 69 in 71bbfb8 it might be possible for us to change this a bit so that hot reloading is set earlier than this. maybe we can change pub trait ExtensionLibrary {
const OVERRIDE_HOT_RELOAD: Option<bool> = None;
}and then match on that value? this would guarantee that we cant panic during the execution of setting the hot reloading value, and ensure it's set before we call any of the panic handling machinery. which is where the issue seemed to come from |
|
I agree with lilizoey here, as mentioned in the earlier review already:
I'm wondering if anyone is using this method at all -- we could just remove it from the public API in v0.3, and use our default implemenation instead. If people complain, we can think about something. |
|
Alternatively, could we change: into I don't think it makes sense to set |
Agree with the first part, not with the second. If anyhow possible, order of initializations should be well-defined, and cause panics whenever a violation occurs. Lazy initialization for bools should be a last resort, because it can quickly lead to non-deterministic or hard-to-debug data flows. Concretely, |
…KevinThierauf/gdext-panic into linux_reload_workaround-changes
|
Unfortunately I don't see a clear way of doing this in a way that doesn't fail |
Currently
linux_reload_workaround.rsstoresHOT_RELOADING_ENABLEDas aOnceCell, which only supports being accessed once. This means that the current implementation ofis_hot_reload_enabled:Sets
HOT_RELOADING_ENABLEDfor the rest of the program, and any future callsenable_hot_reloadfail. Sinceis_hot_reload_enabledis called bythread_atexit,thread_atexitinvocations that occur beforeenable_hot_reloadis called cause a panic.(Unrelated but similar:
disable_hot_reloadnotes// If hot reloading is disabled then we may call this method multiple times.; the current implementation will also cause a panic if called multiple times).I'm specifically encountering this issue with #1037; the
thread_localusage leads tois_hot_reload_enabledfailing.I used some print statements in
is_hot_reload_enabledandenable_hot_reloadto track down the itest failures in #1037:For reference,
private.rs:349:5is:I don't know why, but for whatever reason the initialization of
ERROR_CONTEXT_STACK, which is a thread local value, leads tothread_atexitbeing called. I briefly looked through the rust stdlib source; on 1.84.1 (which I used to compile), it's called by eager.rs.In summary, it seems like using a thread local value on linux that's called before
enable_hot_reloadis called by__gdext_load_libraryleads to callingis_hot_reload_enabled, which leads toenable_hot_reloadfailing.