tornadoweb / tornado

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.
http://www.tornadoweb.org/
Apache License 2.0
21.74k stars 5.5k forks source link

Using vpn causes address assigning error when deploy locally #2247

Closed Takkoona closed 6 years ago

Takkoona commented 6 years ago

Hi,

Kind of new to web developing and tornado here (using version 4.5.3 and web hosting is done by nginx). I was just freaked out by a peculiar error. First, just let me have a little bit explanation on my situation. I'm in a area where extremely strict internet censorship is applied, which blocks some websites that I need for my work. So I bought a commercial vpn to get access to those sites. When I'm not on vpn, tornado works fine with 'localhost'. But, when vpn is on, Debian 9.2 (or 9.3?) doesn't allow me to deploy:

Traceback (most recent call last): File "/home/xxxx/.PyCharmCE2017.3/config/scratches/tornatorial.py", line 45, in <module> http_server.listen(8888, address='localhost') File "/home/xxxx/PycharmProjects/xxxxx/venv/lib/python3.5/site-packages/tornado/tcpserver.py", line 142, in listen sockets = bind_sockets(port, address=address) File "/home/xxxx/PycharmProjects/xxxx/venv/lib/python3.5/site-packages/tornado/netutil.py", line 197, in bind_sockets sock.bind(sockaddr) OSError: [Errno 99] Cannot assign requested address

I thought I would have to turn on and off vpn back and forth to keep work on, which really sucks. But I didn't give up and finally found out that when I'm not using the 'address' argument in 'http_server.listen', it strangely works out!? Basically I just did the following change:

from: http_server.listen(8888, address='localhost') to: http_server.listen(8888)

The issue is already fixed. I'm just so interested in what the hell was happening there and I was so freaked out! Can someone help me out. I appreciate it.

Thank you in advance!

ploxiln commented 6 years ago

http_server.listen(port) without specifying address binds on the "wildcard" address 0.0.0.0 which means "all interfaces", including both your loopback address and your LAN address.

The problem with http_server.listen(8888, address='localhost') is that when you enabled your vpn, it somehow caused 'localhost' to resolve to something other than 127.0.0.1. This has happened to others on test clusters which for some reason have incorrectly-configured ipv6, but in your case is probably some other strange network configuration glitch.

Anyway, you can most likely work around it by doing http_server.listen(8888, address='127.0.0.1') instead.

Takkoona commented 6 years ago

Hi,

Thank you for the reply. Sorry I'm not besides the computer but I can remember, if memory serves, that I tried address='127.0.0.1' and neither did this work for me. Also, another fact that may help is that when vpn is on, and I type 'localhost' in my browser's bar, the nginx welcome page does show up. I will give it another shot after I get access to the computer.

bdarnell commented 6 years ago

This is not normal VPN behavior - I routinely work with a VPN and it doesn't mess with localhost like this. You may want to look into the particular VPN software and service you're using (FWIW, I've had success with privateinternetaccess.com).

Removing the address argument binds to all network interfaces, which could make the server accessible from any network your computer is attached to (other firewall software may prevent this, but it's safer to keep the address argument to make sure). So it would be better to figure out why this isn't working than to just remove the argument. However, this isn't a Tornado issue and we're not in a position to help you figure out what your VPN is doing. Try asking your VPN provider or stack overflow.

Takkoona commented 6 years ago

Just one final closing comment. Tried address='127.0.0.1' and it worked out fine... I think I forgot to specify the address argument the time I did it before posting.