Python Forum
[split] Flask OSError: [Errno 98] Address already in use
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Flask OSError: [Errno 98] Address already in use
#6
(Nov-12-2021, 05:45 PM)venkateshbalagiri Wrote:
(Nov-11-2021, 05:06 PM)ndc85430 Wrote: I mean, it really sounds like a network problem. I disagree when you say it's about a shared directory - why would a web server have knowledge of that?

Does netstat show TCP sockets without -t? Is there more than one interface on the machine? Are the commands looking at all of them (I forget what netstat does by default)?

Out of curiosity, are you on an older Unix that doesn't have ss?

• I mean, it really sounds like a network problem.

<VB> I agree that it sounds like that but with no evidence that the port is actually in use that is why I am pointing to the shared filesystem

• I disagree when you say it's about a shared directory - why would a web server have knowledge of that?

<VB> So a little more background. The directory that hosts this flask app is shared between 2 web servers on different servers. So I was wondering if flask was somehow creating a file that was causing the second webserver to not start as it sees that it is already “running” even though it is on a different server.
The 2 servers are started with their unique host names
source /autohome/www/cgi-bin/Common/flaskenv/bin/activate
cd /autohome/www/cgi-bin/Common
echo "Flask Env Variables has exported"
export FLASK_APP=Glcodes/main.py
export FLASK_DEBUG=True
flask run --host=$(hostname -s).uhc.com

• Does netstat show TCP sockets without -t?

<VB> Yes showing tcp sockets without -t

# netstat -a | grep 5000
tcp 0 0 localhost:55000 localhost:38960 ESTABLISHED
tcp 0 0 localhost:38960 localhost:55000 ESTABLISHED


• Is there more than one interface on the machine?

<VB> No just the primary interface and the standard lo


• Are the commands looking at all of them (I forget what netstat does by default)?

<VB> Shows network status, To display active sockets for each protocol or routing table information.
lsof -i -P -n | grep LISTEN
netstat -tulpn | grep LISTEN
ss -tulpn | grep LISTEN

• Out of curiosity, are you on an older Unix that doesn't have ss?

<VB> We have ss on this server

<VB>
*******Maybe add this to the comments as well

This is part of the code in site-packages/werkzeug/serving.py that seems to be causing the issue. If I comment out the s.bind line the application starts with no issues

if use_reloader:
# If we're not running already in the subprocess that is the
# reloader we want to open up a socket early to make sure the
# port is actually available.
if not is_running_from_reloader():
if port == 0 and not can_open_by_fd:
raise ValueError(
"Cannot bind to a random port with enabled "
"reloader if the Python interpreter does "
"not support socket opening by fd."
)

# Create and destroy a socket so that any exceptions are
# raised before we spawn a separate Python interpreter and
# lose this ability.
address_family = select_address_family(hostname, port)
server_address = get_sockaddr(hostname, port, address_family)
s = socket.socket(address_family, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(server_address)
if hasattr(s, "set_inheritable"):
s.set_inheritable(True)

# If we can open the socket by file descriptor, then we can just
# reuse this one and our socket will survive the restarts.
if can_open_by_fd:
os.environ["WERKZEUG_SERVER_FD"] = str(s.fileno())
s.listen(LISTEN_QUEUE)
log_startup(s)
else:
s.close()
if address_family == af_unix:
_log("info", "Unlinking %s" % server_address)
os.unlink(server_address)

# Do not use relative imports, otherwise "python -m werkzeug.serving"
# breaks.
from ._reloader import run_with_reloader

run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
else:
inner()
Reply


Messages In This Thread
RE: [split] Flask OSError: [Errno 98] Address already in use - by venkateshbalagiri - Nov-17-2021, 01:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] flask 500 internal server error DarthTensor 3 4,037 Nov-11-2021, 06:10 AM
Last Post: DarthTensor

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020