Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_remote_addr return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None ValueError: invalid literal for int() with base 10: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' #1145

Closed
Arryboom opened this issue Aug 11, 2021 · 11 comments

Comments

@Arryboom
Copy link

Checklist

#600
same issue like this old one

Describe the bug

on windows,venv

Package            Version
------------------ ---------
asgiref            3.4.1
certifi            2021.5.30
charset-normalizer 2.0.4
click              8.0.1
colorama           0.4.4
fastapi            0.68.0
greenlet           1.1.0
h11                0.12.0
idna               3.2
Naked              0.1.31
pip                21.2.3
pycryptodome       3.10.1
pydantic           1.8.2
PyYAML             5.4.1
requests           2.26.0
setuptools         57.4.0
shellescape        3.8.1
SQLAlchemy         1.4.22
starlette          0.14.2
typing-extensions  3.10.0.0
urllib3            1.26.6
uvicorn            0.14.0
wheel              0.36.2

To reproduce

  • 1step
    test.py:
from fastapi import FastAPI

app = FastAPI()

@app.get('/')
async def root():
    return {'message': 'hello world'}
  • 2step
    use uvicorn:
uvicorn test:app --reload --port 61111
  • 3step
    open browser and open 127.0.0.1:61111,got no response,and check console
    got
(total) E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend>uvicorn test:app --reload --port 61111
INFO:     Uvicorn running on http://127.0.0.1:61111 (Press CTRL+C to quit)
INFO:     Started reloader process [12332] using statreload
INFO:     Started server process [10352]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
Fatal error in server handler
protocol: <uvicorn.protocols.http.h11_impl.H11Protocol object at 0x00000188B5E8DF10>
transport: <_SelectorSocketTransport fd=904 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\server.py", line 92, in handler
    await handle_http(
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\_handlers\http.py", line 75, in handle_http
    protocol.connection_made(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 85, in connection_made
    self.client = get_remote_addr(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\utils.py", line 13, in get_remote_addr
    return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
ValueError: invalid literal for int() with base 10: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Fatal error in server handler
protocol: <uvicorn.protocols.http.h11_impl.H11Protocol object at 0x00000188B5EA2310>
transport: <_SelectorSocketTransport fd=468 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\server.py", line 92, in handler
    await handle_http(
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\_handlers\http.py", line 75, in handle_http
    protocol.connection_made(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 85, in connection_made
    self.client = get_remote_addr(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\utils.py", line 13, in get_remote_addr
    return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
ValueError: invalid literal for int() with base 10: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Fatal error in server handler
protocol: <uvicorn.protocols.http.h11_impl.H11Protocol object at 0x00000188B5EA26D0>
transport: <_SelectorSocketTransport fd=908 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\server.py", line 92, in handler
    await handle_http(
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\_handlers\http.py", line 75, in handle_http
    protocol.connection_made(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 85, in connection_made
    self.client = get_remote_addr(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\utils.py", line 13, in get_remote_addr
    return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
ValueError: invalid literal for int() with base 10: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
INFO:      - "GET / HTTP/1.1" 200 OK
Fatal error in server handler
protocol: <uvicorn.protocols.http.h11_impl.H11Protocol object at 0x00000188B5E8DF70>
transport: <_SelectorSocketTransport fd=916 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\server.py", line 92, in handler
    await handle_http(
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\_handlers\http.py", line 75, in handle_http
    protocol.connection_made(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 85, in connection_made
    self.client = get_remote_addr(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\utils.py", line 13, in get_remote_addr
    return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
ValueError: invalid literal for int() with base 10: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Fatal error in server handler
protocol: <uvicorn.protocols.http.h11_impl.H11Protocol object at 0x00000188B5EA29D0>
transport: <_SelectorSocketTransport fd=920 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\server.py", line 92, in handler
    await handle_http(
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\_handlers\http.py", line 75, in handle_http
    protocol.connection_made(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 85, in connection_made
    self.client = get_remote_addr(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\utils.py", line 13, in get_remote_addr
    return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
ValueError: invalid literal for int() with base 10: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Fatal error in server handler
protocol: <uvicorn.protocols.http.h11_impl.H11Protocol object at 0x00000188B5EA2B20>
transport: <_SelectorSocketTransport fd=916 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\server.py", line 92, in handler
    await handle_http(
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\_handlers\http.py", line 75, in handle_http
    protocol.connection_made(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 85, in connection_made
    self.client = get_remote_addr(transport)
  File "E:\Desktop_Lite_AfterWin7\tiandao\qinmo_enc\backend\total\lib\site-packages\uvicorn\protocols\utils.py", line 13, in get_remote_addr
    return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
ValueError: invalid literal for int() with base 10: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
INFO:      - "GET / HTTP/1.1" 200 OK

NOTE:

Environment

Running uvicorn 0.14.0 with CPython 3.8.3 on Windows 10 x64

Additional context

@Arryboom
Copy link
Author

try to modify the code in site-packages\uvicorn\protocols\utils.py

def get_remote_addr(transport: asyncio.Transport) -> Optional[Tuple[str, int]]:
    socket_info = transport.get_extra_info("socket")
    if socket_info is not None:
        try:
            info = socket_info.getpeername()
            print("info:")
            print(info)
            return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
        except OSError:
            # This case appears to inconsistently occur with uvloop
            # bound to a unix domain socket.
            return None

got info print as below

info:
(0, b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

@euri10
Copy link
Member

euri10 commented Aug 11, 2021

wont have a windows machine at hand to reproduce that, would you throw up a PR that would make our CI fail ?

@Arryboom
Copy link
Author

wont have a windows machine at hand to reproduce that, would you throw up a PR that would make our CI fail ?

my way to make it back to work quickly is dirty,I just let this socket_info be None,

def get_remote_addr(transport: asyncio.Transport) -> Optional[Tuple[str, int]]:
    socket_info = transport.get_extra_info("socket")
    if socket_info is not None:
        try:
            info = socket_info.getpeername()
            print("info:")
            print(info)
            #return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
            return None
        except OSError:
            # This case appears to inconsistently occur with uvloop
            # bound to a unix domain socket.
            return None

unsure what effects it will produce.

@abersheeran
Copy link
Member

I tried 0.14 and 0.15, but none of them reproduced your problem.

@4XII-Khan
Copy link

4XII-Khan commented Aug 22, 2021

I had the same problem with version 0.15.0 as with the 600 and 1145. At the same time, I tried to shrink the version to 0.14.0 and 0.13.4, but the problem remained.

Describe the bug
on windows 10 , venv

Package           Version
----------------- --------
asgiref           3.4.1
click             7.1.2
colorama          0.4.4
fastapi           0.68.0
h11               0.12.0
httptools         0.2.0
pip               21.2.4
pydantic          1.8.2
python-dotenv     0.19.0
PyYAML            5.4.1
setuptools        56.0.0
starlette         0.14.2
typing-extensions 3.10.0.0
uvicorn           0.13.4
watchgod          0.7
websockets        9.1

My main.py module code is as follows:

from fastapi import FastAPI
import uvicorn
app = FastAPI()


@app.get("/message")
async def root():
    return {"message": "Hello World"}

if __name__ == '__main__':
    uvicorn.run(app='main:app', host="127.0.0.1", port=5000, reload=True, debug=True)

I tried modifying the uvicorn\protocols\utils.py code to print some information, as follow

def get_remote_addr(transport):
    socket_info = transport.get_extra_info("socket")
    print(socket_info)
    if socket_info is not None:
        try:
            info = socket_info.getpeername()
            return (str(info[0]), int(info[1])) if isinstance(info, tuple) else None
        except OSError:
            # This case appears to inconsistently occur with uvloop
            # bound to a unix domain socket.
            return None

When a request is sent, the following information is printed:

<asyncio.TransportSocket fd=588, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 5000), raddr=(0, b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')>

@Arryboom
Copy link
Author

Arryboom commented Sep 3, 2021

it's quite weired problem,when I first use the 0.14 and code I provide above it was normal,but another day rerun its broken.it's totally the same code.and I can only fix it by the way I provided above

@18870
Copy link

18870 commented Jan 15, 2022

LmeSzinc/AzurLaneAutoScript#876 (comment)

Summary

  • Problems occurs only when reload is enabled (--reload), not sure about --workers because we don't use it

Solution

@Kludex
Copy link
Sponsor Member

Kludex commented Oct 29, 2022

Is this still an issue?

@iudeen
Copy link
Contributor

iudeen commented Oct 29, 2022

This title scared me lol

@Kludex
Copy link
Sponsor Member

Kludex commented Dec 12, 2022

Since I can't reproduce the issue, and I didn't receive any reply about it, I'll assume that folks can solve the issue with the comment above: #1145 (comment).

I'll be closing this, but if you have a solution that needs a PR, feel free to create it, and explain how to reproduce, and how the fix works. 🙏

@Kludex Kludex closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2022
@coolmian
Copy link

LmeSzinc/AzurLaneAutoScript#876 (comment)

Summary

  • Problems occurs only when reload is enabled (--reload), not sure about --workers because we don't use it

Solution

Thank you!
I also encountered this issue in uvicorn version 0.26.0, and this command netsh winsock reset saved me!

my environment:
windows10
python3.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants