Skip to content

Default port overrides requesting a system assigned port #2926

@Ben-RK

Description

@Ben-RK

Expected Behavior

When running a flask application with app.run(port=0), flask should pass the '0' port down to werkzeug to use a port assigned by the operating system.

Actual Behavior

The logic in flask/app.py:932 sets the port to the default 5000, which can cause port conflicts, which is the exact situation that setting port=0 should avoid. This is a regression from the behaviour exhibited in prior versions.

>>> app.run(port=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/.../lib/python3.6/site-packages/flask/app.py", line 943, in run
    run_simple(host, port, self, **options)
  File "/.../lib/python3.6/site-packages/werkzeug/serving.py", line 814, in run_simple
    inner()
  File "/.../lib/python3.6/site-packages/werkzeug/serving.py", line 774, in inner
    fd=fd)
  File "/.../lib/python3.6/site-packages/werkzeug/serving.py", line 660, in make_server
    passthrough_errors, ssl_context, fd=fd)
  File ".../lib/python3.6/site-packages/werkzeug/serving.py", line 577, in __init__
    self.address_family), handler)
  File "/.../lib/python3.6/socketserver.py", line 453, in __init__
    self.server_bind()
  File "/.../lib/python3.6/http/server.py", line 136, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/.../lib/python3.6/socketserver.py", line 467, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use

Environment

  • Python version: 3.6
  • Flask version: 1.0.2
  • Werkzeug version: 0.14.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions