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

how can I use plugin configuration in httpContext #207

Open
LugiaChang opened this issue Aug 31, 2023 · 3 comments
Open

how can I use plugin configuration in httpContext #207

LugiaChang opened this issue Aug 31, 2023 · 3 comments

Comments

@LugiaChang
Copy link

LugiaChang commented Aug 31, 2023

My plugin configuration is quite large, and I don't want to clone the plugin configuration every time When I create an httpContext. Can I use Rc::clone() inside Wasm? (Is it may cause memory leak? Im sorry not good at rust) . Or is there any other way for me to get the plugin configuration saved in RootContext from httpContext while avoiding cloning all the data?

struct HttpHeadersRoot {
    wasm_configuration: Rc<WasmConfiguration>,
}

impl RootContext for HttpHeadersRoot {
    fn get_type(&self) -> Option<ContextType> {
        Some(ContextType::HttpContext)
    }

   fn on_configure(&mut self, _: usize) -> bool {
        if let Some(config_bytes) = self.get_plugin_configuration() {
            if str::from_utf8(&config_bytes).is_err() {
                return false;
            }
            let t: WasmConfiguration = serde_json::from_str(str::from_utf8(&config_bytes).unwrap()).unwrap();
            self.wasm_configuration = Rc::new(t);
            return true
        } else {
            return false;
        }
    }

    fn create_http_context(&self, _: u32) -> Option<Box<dyn HttpContext>> {
        Some(Box::new(HttpHeaders {
            wasm_configuration: Rc::clone(&self.wasm_configuration),
        }))
    }
}
@antonengelhardt
Copy link

I used an Arc @LugiaChang

@LugiaChang
Copy link
Author

I used an Arc @LugiaChang

Is Wasm single thread? I'm not quite sure.

@pi-pi-miao
Copy link

单线程的,每次请求结束之后会通过 drop 把数据释放掉,所以不存在内存泄露

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

3 participants