leaningtech/webvm

getaddrinfo doesn't work with an Alpine image

mattx433 opened this issue · 1 comments

Using Mini.WebVM and this Dockerfile: https://github.com/mattx433/webvm/blob/main/dockerfiles/alpine getaddrinfo fails with various programs:

:~$ curl 1.1.1.1
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
:~$ curl httpbin.org/get
curl: (6) Could not resolve host: httpbin.org
:~$ 
:~$ python3
Python 3.11.3 (main, May 10 2023, 12:26:31) [GCC 12.2.1 20220924] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.request import urlopen
>>> a = urllib.request.urlopen("http://httpbin.org/get")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'urllib' is not defined
>>> a = urlopen("http://httpbin.org/get")               
Traceback (most recent call last):
  File "/usr/lib/python3.11/urllib/request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/lib/python3.11/http/client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.11/http/client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.11/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.11/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/usr/lib/python3.11/http/client.py", line 976, in send
    self.connect()
  File "/usr/lib/python3.11/http/client.py", line 942, in connect
    self.sock = self._create_connection(
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/socket.py", line 827, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/socket.py", line 962, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -3] Try again
[snip]

Commands to reproduce:

  • curl httpbin.org/get
  • python3 -c 'import socket; socket.getaddrinfo("httpbin.org", "80")'
  • python3 -c 'import urllib.request; urllib.request.urlopen("http://httpbin.org/get")'

This problem is fixed with the current latest build, there was a mistake in the implementation of the send syscall for datagram sockets.

Reference build: https://cheerpxdemos.leaningtech.com/publicdeploy/20230608_106/cx.js