We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
bug: module 'socket' has no attribute 'AF_UNIX'
### Describe the bug

Hello,
I'm trying to use Bentoml by playing with the quick start examples. When running the Iris classification example on a windows machine, I have this error message:
```
File "C:\Users\Path\lib\site-packages\uvicorn\server.py", line 140, in startup
    sock = socket.fromfd(config.fd, socket.AF_UNIX, socket.SOCK_STREAM)
AttributeError: module 'socket' has no attribute 'AF_UNIX'
```

I tried to change the socket attribute to AF_INET, the error messages disappear but the client cannot connect to the bentoml server.

Thanks,


### To reproduce

_No response_

### Expected behavior

_No response_

### Environment

bentoml:1.2.12
python:3.9.18
uvicorn:0.29.0
Windows: 11 Pro 22H2

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/_bentoml_impl/worker/service.py`
Content:
```
1 from __future__ import annotations
2 
3 import json
4 import os
5 import typing as t
6 
7 import click
8 
9 
10 @click.command()
11 @click.argument("bento_identifier", type=click.STRING, required=False, default=".")
12 @click.option("--service-name", type=click.STRING, required=False, default="")
13 @click.option(
14     "--fd",
15     type=click.INT,
16     required=True,
17     help="File descriptor of the socket to listen on",
18 )
19 @click.option(
20     "--runner-map",
21     type=click.STRING,
22     envvar="BENTOML_RUNNER_MAP",
23     help="JSON string of runners map, default sets to envars `BENTOML_RUNNER_MAP`",
24 )
25 @click.option(
26     "--backlog", type=click.INT, default=2048, help="Backlog size for the socket"
27 )
28 @click.option(
29     "--prometheus-dir",
30     type=click.Path(exists=True),
31     help="Required by prometheus to pass the metrics in multi-process mode",
32 )
33 @click.option(
34     "--worker-env", type=click.STRING, default=None, help="Environment variables"
35 )
36 @click.option(
37     "--worker-id",
38     required=False,
39     type=click.INT,
40     default=None,
41     help="If set, start the server as a bare worker with the given worker ID. Otherwise start a standalone server with a supervisor process.",
42 )
43 @click.option(
44     "--ssl-certfile",
45     type=str,
46     default=None,
47     help="SSL certificate file",
48 )
49 @click.option(
50     "--ssl-keyfile",
51     type=str,
52     default=None,
53     help="SSL key file",
54 )
55 @click.option(
56     "--ssl-keyfile-password",
57     type=str,
58     default=None,
59     help="SSL keyfile password",
60 )
61 @click.option(
62     "--ssl-version",
63     type=int,
64     default=None,
65     help="SSL version to use (see stdlib 'ssl' module)",
66 )
67 @click.option(
68     "--ssl-cert-reqs",
69     type=int,
70     default=None,
71     help="Whether client certificate is required (see stdlib 'ssl' module)",
72 )
73 @click.option(
74     "--ssl-ca-certs",
75     type=str,
76     default=None,
77     help="CA certificates file",
78 )
79 @click.option(
80     "--ssl-ciphers",
81     type=str,
82     default=None,
83     help="Ciphers to use (see stdlib 'ssl' module)",
84 )
85 @click.option(
86     "--development-mode",
87     type=click.BOOL,
88     help="Run the API server in development mode",
89     is_flag=True,
90     default=False,
91     show_default=True,
92 )
93 @click.option(
94     "--timeout",
95     type=click.INT,
96     help="Specify the timeout for API server",
97 )
98 def main(
99     bento_identifier: str,
100     service_name: str,
101     fd: int,
102     runner_map: str | None,
103     backlog: int,
104     worker_env: str | None,
105     worker_id: int | None,
106     prometheus_dir: str | None,
107     ssl_certfile: str | None,
108     ssl_keyfile: str | None,
109     ssl_keyfile_password: str | None,
110     ssl_version: int | None,
111     ssl_cert_reqs: int | None,
112     ssl_ca_certs: str | None,
113     ssl_ciphers: str | None,
114     development_mode: bool,
115     timeout: int,
116 ):
117     """
118     Start a HTTP server worker for given service.
119     """
120     import psutil
121     import uvicorn
122 
123     if worker_env:
124         env_list: list[dict[str, t.Any]] = json.loads(worker_env)
125         if worker_id is not None:
126             # worker id from circus starts from 1
127             worker_key = worker_id - 1
128             if worker_key >= len(env_list):
129                 raise IndexError(
130                     f"Worker ID {worker_id} is out of range, "
131                     f"the maximum worker ID is {len(env_list)}"
132                 )
133             os.environ.update(env_list[worker_key])
134 
135     from _bentoml_impl.loader import import_service
136     from bentoml._internal.container import BentoMLContainer
137     from bentoml._internal.context import server_context
138     from bentoml._internal.log import configure_server_logging
139 
140     if runner_map:
141         BentoMLContainer.remote_runner_mapping.set(
142             t.cast(t.Dict[str, str], json.loads(runner_map))
143         )
144 
145     service = import_service(bento_identifier)
146 
147     if service_name and service_name != service.name:
148         service = service.find_dependent(service_name)
149         server_context.service_type = "service"
150     else:
151         server_context.service_type = "entry_service"
152 
153     if worker_id is not None:
154         server_context.worker_index = worker_id
155 
156     configure_server_logging()
157     BentoMLContainer.development_mode.set(development_mode)
158 
159     if prometheus_dir is not None:
160         BentoMLContainer.prometheus_multiproc_dir.set(prometheus_dir)
161     server_context.service_name = service.name
162 
163     asgi_app = service.to_asgi(
164         is_main=server_context.service_type == "entry_service", init=False
165     )
166 
167     uvicorn_extra_options: dict[str, t.Any] = {}
168     if ssl_version is not None:
169         uvicorn_extra_options["ssl_version"] = ssl_version
170     if ssl_cert_reqs is not None:
171         uvicorn_extra_options["ssl_cert_reqs"] = ssl_cert_reqs
172     if ssl_ciphers is not None:
173         uvicorn_extra_options["ssl_ciphers"] = ssl_ciphers
174 
175     if psutil.WINDOWS:
176         # 1. uvloop is not supported on Windows
177         # 2. the default policy for Python > 3.8 on Windows is ProactorEventLoop, which doesn't
178         #    support listen on a existing socket file descriptors
179         # See https://docs.python.org/3.8/library/asyncio-platforms.html#windows
180         uvicorn_extra_options["loop"] = "asyncio"
181         import asyncio
182 
183         asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())  # type: ignore
184 
185     uvicorn.run(
186         app=asgi_app,
187         fd=fd,
188         backlog=backlog,
189         log_config=None,
190         workers=1,
191         ssl_certfile=ssl_certfile,
192         ssl_keyfile=ssl_keyfile,
193         ssl_keyfile_password=ssl_keyfile_password,
194         ssl_ca_certs=ssl_ca_certs,
195         server_header=False,
196         **uvicorn_extra_options,
197     )
198 
199 
200 if __name__ == "__main__":
201     main()  # pylint: disable=no-value-for-parameter
202
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/_bentoml_impl/worker/service.py b/src/_bentoml_impl/worker/service.py
--- a/src/_bentoml_impl/worker/service.py
+++ b/src/_bentoml_impl/worker/service.py
@@ -117,6 +117,8 @@
     """
     Start a HTTP server worker for given service.
     """
+    import socket
+
     import psutil
     import uvicorn
 
@@ -182,9 +184,8 @@
 
         asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())  # type: ignore
 
-    uvicorn.run(
+    config = uvicorn.Config(
         app=asgi_app,
-        fd=fd,
         backlog=backlog,
         log_config=None,
         workers=1,
@@ -195,6 +196,8 @@
         server_header=False,
         **uvicorn_extra_options,
     )
+    socket = socket.socket(fileno=fd)
+    uvicorn.Server(config).run(sockets=[socket])
 
 
 if __name__ == "__main__":

{"golden_diff": "diff --git a/src/_bentoml_impl/worker/service.py b/src/_bentoml_impl/worker/service.py\n--- a/src/_bentoml_impl/worker/service.py\n+++ b/src/_bentoml_impl/worker/service.py\n@@ -117,6 +117,8 @@\n     \"\"\"\n     Start a HTTP server worker for given service.\n     \"\"\"\n+    import socket\n+\n     import psutil\n     import uvicorn\n \n@@ -182,9 +184,8 @@\n \n         asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())  # type: ignore\n \n-    uvicorn.run(\n+    config = uvicorn.Config(\n         app=asgi_app,\n-        fd=fd,\n         backlog=backlog,\n         log_config=None,\n         workers=1,\n@@ -195,6 +196,8 @@\n         server_header=False,\n         **uvicorn_extra_options,\n     )\n+    socket = socket.socket(fileno=fd)\n+    uvicorn.Server(config).run(sockets=[socket])\n \n \n if __name__ == \"__main__\":\n", "issue": "bug: module 'socket' has no attribute 'AF_UNIX'\n### Describe the bug\r\n\r\nHello,\r\nI'm trying to use Bentoml by playing with the quick start examples. When running the Iris classification example on a windows machine, I have this error message:\r\n```\r\nFile \"C:\\Users\\Path\\lib\\site-packages\\uvicorn\\server.py\", line 140, in startup\r\n    sock = socket.fromfd(config.fd, socket.AF_UNIX, socket.SOCK_STREAM)\r\nAttributeError: module 'socket' has no attribute 'AF_UNIX'\r\n```\r\n\r\nI tried to change the socket attribute to AF_INET, the error messages disappear but the client cannot connect to the bentoml server.\r\n\r\nThanks,\r\n\r\n\r\n### To reproduce\r\n\r\n_No response_\r\n\r\n### Expected behavior\r\n\r\n_No response_\r\n\r\n### Environment\r\n\r\nbentoml:1.2.12\r\npython:3.9.18\r\nuvicorn:0.29.0\r\nWindows: 11 Pro 22H2\n", "before_files": [{"content": "from __future__ import annotations\n\nimport json\nimport os\nimport typing as t\n\nimport click\n\n\n@click.command()\n@click.argument(\"bento_identifier\", type=click.STRING, required=False, default=\".\")\n@click.option(\"--service-name\", type=click.STRING, required=False, default=\"\")\n@click.option(\n    \"--fd\",\n    type=click.INT,\n    required=True,\n    help=\"File descriptor of the socket to listen on\",\n)\n@click.option(\n    \"--runner-map\",\n    type=click.STRING,\n    envvar=\"BENTOML_RUNNER_MAP\",\n    help=\"JSON string of runners map, default sets to envars `BENTOML_RUNNER_MAP`\",\n)\n@click.option(\n    \"--backlog\", type=click.INT, default=2048, help=\"Backlog size for the socket\"\n)\n@click.option(\n    \"--prometheus-dir\",\n    type=click.Path(exists=True),\n    help=\"Required by prometheus to pass the metrics in multi-process mode\",\n)\n@click.option(\n    \"--worker-env\", type=click.STRING, default=None, help=\"Environment variables\"\n)\n@click.option(\n    \"--worker-id\",\n    required=False,\n    type=click.INT,\n    default=None,\n    help=\"If set, start the server as a bare worker with the given worker ID. Otherwise start a standalone server with a supervisor process.\",\n)\n@click.option(\n    \"--ssl-certfile\",\n    type=str,\n    default=None,\n    help=\"SSL certificate file\",\n)\n@click.option(\n    \"--ssl-keyfile\",\n    type=str,\n    default=None,\n    help=\"SSL key file\",\n)\n@click.option(\n    \"--ssl-keyfile-password\",\n    type=str,\n    default=None,\n    help=\"SSL keyfile password\",\n)\n@click.option(\n    \"--ssl-version\",\n    type=int,\n    default=None,\n    help=\"SSL version to use (see stdlib 'ssl' module)\",\n)\n@click.option(\n    \"--ssl-cert-reqs\",\n    type=int,\n    default=None,\n    help=\"Whether client certificate is required (see stdlib 'ssl' module)\",\n)\n@click.option(\n    \"--ssl-ca-certs\",\n    type=str,\n    default=None,\n    help=\"CA certificates file\",\n)\n@click.option(\n    \"--ssl-ciphers\",\n    type=str,\n    default=None,\n    help=\"Ciphers to use (see stdlib 'ssl' module)\",\n)\n@click.option(\n    \"--development-mode\",\n    type=click.BOOL,\n    help=\"Run the API server in development mode\",\n    is_flag=True,\n    default=False,\n    show_default=True,\n)\n@click.option(\n    \"--timeout\",\n    type=click.INT,\n    help=\"Specify the timeout for API server\",\n)\ndef main(\n    bento_identifier: str,\n    service_name: str,\n    fd: int,\n    runner_map: str | None,\n    backlog: int,\n    worker_env: str | None,\n    worker_id: int | None,\n    prometheus_dir: str | None,\n    ssl_certfile: str | None,\n    ssl_keyfile: str | None,\n    ssl_keyfile_password: str | None,\n    ssl_version: int | None,\n    ssl_cert_reqs: int | None,\n    ssl_ca_certs: str | None,\n    ssl_ciphers: str | None,\n    development_mode: bool,\n    timeout: int,\n):\n    \"\"\"\n    Start a HTTP server worker for given service.\n    \"\"\"\n    import psutil\n    import uvicorn\n\n    if worker_env:\n        env_list: list[dict[str, t.Any]] = json.loads(worker_env)\n        if worker_id is not None:\n            # worker id from circus starts from 1\n            worker_key = worker_id - 1\n            if worker_key >= len(env_list):\n                raise IndexError(\n                    f\"Worker ID {worker_id} is out of range, \"\n                    f\"the maximum worker ID is {len(env_list)}\"\n                )\n            os.environ.update(env_list[worker_key])\n\n    from _bentoml_impl.loader import import_service\n    from bentoml._internal.container import BentoMLContainer\n    from bentoml._internal.context import server_context\n    from bentoml._internal.log import configure_server_logging\n\n    if runner_map:\n        BentoMLContainer.remote_runner_mapping.set(\n            t.cast(t.Dict[str, str], json.loads(runner_map))\n        )\n\n    service = import_service(bento_identifier)\n\n    if service_name and service_name != service.name:\n        service = service.find_dependent(service_name)\n        server_context.service_type = \"service\"\n    else:\n        server_context.service_type = \"entry_service\"\n\n    if worker_id is not None:\n        server_context.worker_index = worker_id\n\n    configure_server_logging()\n    BentoMLContainer.development_mode.set(development_mode)\n\n    if prometheus_dir is not None:\n        BentoMLContainer.prometheus_multiproc_dir.set(prometheus_dir)\n    server_context.service_name = service.name\n\n    asgi_app = service.to_asgi(\n        is_main=server_context.service_type == \"entry_service\", init=False\n    )\n\n    uvicorn_extra_options: dict[str, t.Any] = {}\n    if ssl_version is not None:\n        uvicorn_extra_options[\"ssl_version\"] = ssl_version\n    if ssl_cert_reqs is not None:\n        uvicorn_extra_options[\"ssl_cert_reqs\"] = ssl_cert_reqs\n    if ssl_ciphers is not None:\n        uvicorn_extra_options[\"ssl_ciphers\"] = ssl_ciphers\n\n    if psutil.WINDOWS:\n        # 1. uvloop is not supported on Windows\n        # 2. the default policy for Python > 3.8 on Windows is ProactorEventLoop, which doesn't\n        #    support listen on a existing socket file descriptors\n        # See https://docs.python.org/3.8/library/asyncio-platforms.html#windows\n        uvicorn_extra_options[\"loop\"] = \"asyncio\"\n        import asyncio\n\n        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())  # type: ignore\n\n    uvicorn.run(\n        app=asgi_app,\n        fd=fd,\n        backlog=backlog,\n        log_config=None,\n        workers=1,\n        ssl_certfile=ssl_certfile,\n        ssl_keyfile=ssl_keyfile,\n        ssl_keyfile_password=ssl_keyfile_password,\n        ssl_ca_certs=ssl_ca_certs,\n        server_header=False,\n        **uvicorn_extra_options,\n    )\n\n\nif __name__ == \"__main__\":\n    main()  # pylint: disable=no-value-for-parameter\n", "path": "src/_bentoml_impl/worker/service.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport json\nimport os\nimport typing as t\n\nimport click\n\n\n@click.command()\n@click.argument(\"bento_identifier\", type=click.STRING, required=False, default=\".\")\n@click.option(\"--service-name\", type=click.STRING, required=False, default=\"\")\n@click.option(\n    \"--fd\",\n    type=click.INT,\n    required=True,\n    help=\"File descriptor of the socket to listen on\",\n)\n@click.option(\n    \"--runner-map\",\n    type=click.STRING,\n    envvar=\"BENTOML_RUNNER_MAP\",\n    help=\"JSON string of runners map, default sets to envars `BENTOML_RUNNER_MAP`\",\n)\n@click.option(\n    \"--backlog\", type=click.INT, default=2048, help=\"Backlog size for the socket\"\n)\n@click.option(\n    \"--prometheus-dir\",\n    type=click.Path(exists=True),\n    help=\"Required by prometheus to pass the metrics in multi-process mode\",\n)\n@click.option(\n    \"--worker-env\", type=click.STRING, default=None, help=\"Environment variables\"\n)\n@click.option(\n    \"--worker-id\",\n    required=False,\n    type=click.INT,\n    default=None,\n    help=\"If set, start the server as a bare worker with the given worker ID. Otherwise start a standalone server with a supervisor process.\",\n)\n@click.option(\n    \"--ssl-certfile\",\n    type=str,\n    default=None,\n    help=\"SSL certificate file\",\n)\n@click.option(\n    \"--ssl-keyfile\",\n    type=str,\n    default=None,\n    help=\"SSL key file\",\n)\n@click.option(\n    \"--ssl-keyfile-password\",\n    type=str,\n    default=None,\n    help=\"SSL keyfile password\",\n)\n@click.option(\n    \"--ssl-version\",\n    type=int,\n    default=None,\n    help=\"SSL version to use (see stdlib 'ssl' module)\",\n)\n@click.option(\n    \"--ssl-cert-reqs\",\n    type=int,\n    default=None,\n    help=\"Whether client certificate is required (see stdlib 'ssl' module)\",\n)\n@click.option(\n    \"--ssl-ca-certs\",\n    type=str,\n    default=None,\n    help=\"CA certificates file\",\n)\n@click.option(\n    \"--ssl-ciphers\",\n    type=str,\n    default=None,\n    help=\"Ciphers to use (see stdlib 'ssl' module)\",\n)\n@click.option(\n    \"--development-mode\",\n    type=click.BOOL,\n    help=\"Run the API server in development mode\",\n    is_flag=True,\n    default=False,\n    show_default=True,\n)\n@click.option(\n    \"--timeout\",\n    type=click.INT,\n    help=\"Specify the timeout for API server\",\n)\ndef main(\n    bento_identifier: str,\n    service_name: str,\n    fd: int,\n    runner_map: str | None,\n    backlog: int,\n    worker_env: str | None,\n    worker_id: int | None,\n    prometheus_dir: str | None,\n    ssl_certfile: str | None,\n    ssl_keyfile: str | None,\n    ssl_keyfile_password: str | None,\n    ssl_version: int | None,\n    ssl_cert_reqs: int | None,\n    ssl_ca_certs: str | None,\n    ssl_ciphers: str | None,\n    development_mode: bool,\n    timeout: int,\n):\n    \"\"\"\n    Start a HTTP server worker for given service.\n    \"\"\"\n    import socket\n\n    import psutil\n    import uvicorn\n\n    if worker_env:\n        env_list: list[dict[str, t.Any]] = json.loads(worker_env)\n        if worker_id is not None:\n            # worker id from circus starts from 1\n            worker_key = worker_id - 1\n            if worker_key >= len(env_list):\n                raise IndexError(\n                    f\"Worker ID {worker_id} is out of range, \"\n                    f\"the maximum worker ID is {len(env_list)}\"\n                )\n            os.environ.update(env_list[worker_key])\n\n    from _bentoml_impl.loader import import_service\n    from bentoml._internal.container import BentoMLContainer\n    from bentoml._internal.context import server_context\n    from bentoml._internal.log import configure_server_logging\n\n    if runner_map:\n        BentoMLContainer.remote_runner_mapping.set(\n            t.cast(t.Dict[str, str], json.loads(runner_map))\n        )\n\n    service = import_service(bento_identifier)\n\n    if service_name and service_name != service.name:\n        service = service.find_dependent(service_name)\n        server_context.service_type = \"service\"\n    else:\n        server_context.service_type = \"entry_service\"\n\n    if worker_id is not None:\n        server_context.worker_index = worker_id\n\n    configure_server_logging()\n    BentoMLContainer.development_mode.set(development_mode)\n\n    if prometheus_dir is not None:\n        BentoMLContainer.prometheus_multiproc_dir.set(prometheus_dir)\n    server_context.service_name = service.name\n\n    asgi_app = service.to_asgi(\n        is_main=server_context.service_type == \"entry_service\", init=False\n    )\n\n    uvicorn_extra_options: dict[str, t.Any] = {}\n    if ssl_version is not None:\n        uvicorn_extra_options[\"ssl_version\"] = ssl_version\n    if ssl_cert_reqs is not None:\n        uvicorn_extra_options[\"ssl_cert_reqs\"] = ssl_cert_reqs\n    if ssl_ciphers is not None:\n        uvicorn_extra_options[\"ssl_ciphers\"] = ssl_ciphers\n\n    if psutil.WINDOWS:\n        # 1. uvloop is not supported on Windows\n        # 2. the default policy for Python > 3.8 on Windows is ProactorEventLoop, which doesn't\n        #    support listen on a existing socket file descriptors\n        # See https://docs.python.org/3.8/library/asyncio-platforms.html#windows\n        uvicorn_extra_options[\"loop\"] = \"asyncio\"\n        import asyncio\n\n        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())  # type: ignore\n\n    config = uvicorn.Config(\n        app=asgi_app,\n        backlog=backlog,\n        log_config=None,\n        workers=1,\n        ssl_certfile=ssl_certfile,\n        ssl_keyfile=ssl_keyfile,\n        ssl_keyfile_password=ssl_keyfile_password,\n        ssl_ca_certs=ssl_ca_certs,\n        server_header=False,\n        **uvicorn_extra_options,\n    )\n    socket = socket.socket(fileno=fd)\n    uvicorn.Server(config).run(sockets=[socket])\n\n\nif __name__ == \"__main__\":\n    main()  # pylint: disable=no-value-for-parameter\n", "path": "src/_bentoml_impl/worker/service.py"}]}