-
Notifications
You must be signed in to change notification settings - Fork 104
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
Issues with old plugin not unloading correctly. (TLS + Linux) #35
Comments
Looks like a crash from
|
I found the problem.
At step 5 I did a quick hack in |
Interesting find. I think we may be missing something when closing the handle or it may be something related to file inodes. Not sure, I'll try to do some research on this, but looking at this, it is bad. We need to find the source and fix there. Can you please confirm you're able to reproduce this only with the cr c samples? Just to be sure this is nothing related to how rustc is building the app/libs. |
I was thinking it was do to TLS usage causing |
I haven't been able to cause a C guest to stay loaded. I was able to load a Rust guest plugin in the |
Final made a Rust plugin that unloads correctly: use std::os::raw::{c_int, c_void};
#[no_mangle]
pub fn cr_main(_ctx: *mut c_void, _cr_op: c_int) -> c_int {
//println!("From Rust!"); // this print will prevent the plugin from unloading.
return 1; // change number with each compile.
} I read somewhere that |
This problem doesn't happen on Windows. The Rust plugin rollback and reload seem to work just fine. I haven't tested MacOS. Maybe this is a Rust only issue on Linux. |
Final made a c++ example that uses TLS destructors that has the same issue: #include <string>
#include <stdio.h>
#include "../cr.h"
thread_local std::string tls_str("hello tls");
CR_EXPORT int cr_main(struct cr_plugin *ctx, enum cr_op operation) {
fprintf(stdout, "tls_str = '%s'\n", tls_str.c_str());
return 0;
} |
Compiling the C++ TLS plugin with |
FYI, found that compiler flag on this stackoverflow answer |
I can't find anyway to disable But I think the only safe option right now is to either not unload the plugin or use unique file names. |
That is a really interesting finding. Yeah, so I'd imagine that you'll need to provide this symbol in your crate in someway. This may help: rust-lang/rust#36826 |
I tried defining Only defining it in the host (disabling TLS destructors for the whole program) will make it work for Rust plugins. C++ plugins can work with But doing those hack will disable thread_local destructors, which could be useful. Until I find a way to force Also I found out why rollback + reload was crashing before when the file name was reused. The rollback didn't unload the old version (still had live references from TLS), so the next P.S. I did find a way to detect if a shared library used TLS data. Call |
The pointer returned from Anyway, good job investigating all this another c++ foot gun instance. In the end, C reload is basically unaware of C++ idiosyncrasies, unfortunately this seems to pretty much map into Rust domain too. |
It really was invalid. I was even tracking the It almost seems to be a bug in I think the next step would be to dive into |
I found a way to catch panics from Rust guest plugins. But there seems to be a problem when
cr
does a reload after a rollback. Maybe a segfault happens in thecr
reload code and it tries tosiglongjmp
back tocr_plugin_main()
?Might be useful to have an option to disable the
setjmp
/exception handling for a plugin.This is the commit I was using:
Neopallium/cr-sys@8b7853c
With
CR_DEBUG
defined insrc/host.cpp
.Output running under valgrind:
cr-sys-rollback-reload.log
The text was updated successfully, but these errors were encountered: