Repository: sanic-org/sanic

Issue:
AttributeError: 'NoneType' object has no attribute 'share' when using the async server
**Describe the bug**
I'm trying to run a slightly modified version of https://github.com/sanic-org/sanic/blob/main/examples/run_async.py, where I switched `uvloop.new_event_loop()` for the builtin `asyncio.new_event_loop()`. This works in Sanic 22.6.2, but breaks in 22.9.0 with the following error message

```
Traceback (most recent call last):
  File "C:\<path>\sanic_test.py", line 28, in <module>
    asyncio.run(main())
  File "C:\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File ""C:\<path>\sanic_test.py", line 15, in main
    server = await app.create_server(
  File ""C:\<path>\venv\lib\site-packages\sanic\mixins\startup.py", line 450, in create_server    return await serve(
  File ""C:\<path>\venv\lib\site-packages\sanic\server\runners.py", line 106, in serve        
    return _serve_http_1(
  File ""C:\<path>\venv\lib\site-packages\sanic\server\runners.py", line 205, in _serve_http_1    sock = sock.share(pid)
AttributeError: 'NoneType' object has no attribute 'share'
```

**Code snippet**
https://github.com/sanic-org/sanic/blob/main/examples/run_async.py with `uvloop.new_event_loop()` replaced with `asyncio.new_event_loop()`.

**Expected behavior**
The server starts.

**Environment (please complete the following information):**
<!-- Please provide the information below. Instead, you can copy and paste the message that Sanic shows on startup. If you do, please remember to format it with ``` -->
```
  ┌─────────────────────────────────────────────────────────────┐
  │                        Sanic v22.9.0                        │
  │               Goin' Fast @ http://0.0.0.0:8000              │
  ├───────────────────────┬─────────────────────────────────────┤
  │                       │     mode: production, single worker │
  │     ▄███ █████ ██     │   server: sanic, HTTP/1.1           │
  │    ██                 │   python: 3.10.4                    │
  │     ▀███████ ███▄     │ platform: Windows-10-10.0.19043-SP0 │
  │                 ██    │ packages: sanic-routing==22.8.0     │
  │    ████ ████████▀     │                                     │
  │                       │                                     │
  │ Build Fast. Run Fast. │                                     │
  └───────────────────────┴─────────────────────────────────────┘
```

**Additional context**
<!-- Add any other context about the problem here. -->



Discussion:
I see the issue. Will get a patch out for this shortly. Thanks for bringing this up. Surprised the CI didn't catch this TBH.
Couldn't reproduce it. Already fixed?
> Couldn't reproduce it. Already fixed?

Did you use Windows?

Resolving patch:
diff --git a/sanic/server/runners.py b/sanic/server/runners.py
--- a/sanic/server/runners.py
+++ b/sanic/server/runners.py
@@ -200,7 +200,7 @@ def _serve_http_1(
     asyncio_server_kwargs = (
         asyncio_server_kwargs if asyncio_server_kwargs else {}
     )
-    if OS_IS_WINDOWS:
+    if OS_IS_WINDOWS and sock:
         pid = os.getpid()
         sock = sock.share(pid)
         sock = socket.fromshare(sock)


Test patch: