webassembly-language-runtimes icon indicating copy to clipboard operation
webassembly-language-runtimes copied to clipboard

python: wasmedge docker image hangs when importing the socket package

Open achille-roussel opened this issue 2 years ago • 3 comments

Describe the bug

When importing the socket package, the program hangs and may only be interrupted by termination via a signal.

Reproduction steps

$ docker run --rm \
  -i \
  --runtime=io.containerd.wasmedge.v1 \
  --platform=wasm32/wasi \
  ghcr.io/vmware-labs/python-wasm:3.11.1-wasmedge \
  -i
Python 3.11.1 (tags/v3.11.1:a7a450f, Feb 17 2023, 11:01:02) [Clang 15.0.7 ] on wasi
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket

Expected behavior

The documentation appears to say that networking with Python is possible when using the build leveraging the WasmEdge socket API extensions. I expected to be able to import the socket package and either create a TCP client or server.

Additional context

No response

achille-roussel avatar Apr 25 '23 04:04 achille-roussel

You are right! The documentation is misleading in this case. I will correct it shortly. Here is the issue we have to track integrating WasmEdge sockets with CPython - https://github.com/vmware-labs/webassembly-language-runtimes/issues/70

The reason we have a separate build is purely for the sake of the sock_accept method which has different signature in wasi_preview_1 and with WasmEdge.

assambar avatar Apr 25 '23 07:04 assambar

Thanks a lot for pointing this out!

@achille-roussel , on a side note - is socket support in Python something for which you have some immediate business need , or are you just experimenting?

Asking to help us prioritize. Thanks!

assambar avatar Apr 25 '23 07:04 assambar

I'm exploring what currently exists in the industry for networking with WASI. The use case is implementing it in Go, and I would like to stay as close to something that already exists for interoperability between languages and runtimes.

Based on this comment it appears that wasmedge corrected their implementation of sock_accept in v0.12+ https://github.com/WasmEdge/WasmEdge/blob/master/lib/host/wasi/wasimodule.cpp#L64-L73 Maybe you won't need to ship a different build in the future :)

  // To make the socket API compatible with the old one,
  // we will duplicate all the API to V1 and V2.
  // The V1 presents the original behavior before 0.12 release.
  // On the other hand, the V2 presents the new behavior including
  // the sock_accept is following the WASI spec, some of the API
  // use a larger size for handling complex address type, e.g.
  // AF_UNIX.
  // By default, we will register V1 first, if the signatures are
  // not the same as the wasm application imported, then V2 will
  // replace instead.

achille-roussel avatar Apr 25 '23 17:04 achille-roussel