second-state / wasmedge-quickjs

A high-performance, secure, extensible, and OCI-complaint JavaScript runtime for WasmEdge.
Apache License 2.0
494 stars 60 forks source link

example_hs/wasi_http_fetch.js returns "InternalError: invalid socket address syntax" on macOS #141

Open tritonrc opened 3 months ago

tritonrc commented 3 months ago

I was playing with wasmedge + quickjs last night (thank you all for the great work here!) when I ran into an error with the http fetch examples.

Each one returned "InternalError: invalid socket address syntax"

After digging around on the internet I stumbled on to_socket_addrs (line 475 in src/internal_module/wasi_net_module.rs) as the culprit.

Changing this line to the following:

diff --git a/src/internal_module/wasi_net_module.rs b/src/internal_module/wasi_net_module.rs
index 3991f33..764ddb7 100644
--- a/src/internal_module/wasi_net_module.rs
+++ b/src/internal_module/wasi_net_module.rs
@@ -472,7 +472,7 @@ fn js_nsloopup(ctx: &mut Context, _this: JsValue, param: &[JsValue]) -> JsValue
     let node = param.get(0);
     let service = param.get(1);
     if let (Some(JsValue::String(node)), Some(JsValue::String(service))) = (node, service) {
-        let r = format!("{}:{}", node.as_str(), service.as_str()).to_socket_addrs();
+        let r = (node.as_str(), service.as_str().parse::<u16>().unwrap_or(0)).to_socket_addrs();
         match r {
             Ok(addr_vec) => {
                 let mut array = ctx.new_array();

did the trick and I was able to run the http fetch tests successfully on my Mac.

L-jasmine commented 1 month ago

Thank you for your questions and solutions. I think something has gone wrong at a lower level. I will check it