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

Default port overrides requesting a system assigned port #2926

Closed
Ben-RK opened this issue Sep 28, 2018 · 8 comments · Fixed by #2928
Closed

Default port overrides requesting a system assigned port #2926

Ben-RK opened this issue Sep 28, 2018 · 8 comments · Fixed by #2928
Milestone

Comments

@Ben-RK
Copy link

Ben-RK commented Sep 28, 2018

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
@davidism davidism added this to the 1.0.3 milestone Sep 28, 2018
@davidism
Copy link
Member

Makes sense. Marking this as beginner friendly, I'd be happy to review a PR.

@vorelq
Copy link
Contributor

vorelq commented Sep 28, 2018

Hi, I'd like to try and fix this one.

@patiencedaur
Copy link

patiencedaur commented Oct 13, 2018

I think it's closed, it shows expected behavior

@Man-Jain
Copy link

Man-Jain commented Nov 5, 2018

Is this one still up for grabs ?

@ThiefMaster
Copy link
Member

No, there's a PR for it (see above)

@Man-Jain
Copy link

Man-Jain commented Nov 5, 2018

Yeah but it as inactive for over a month. That's why I asked.

@theodesp
Copy link

theodesp commented Dec 1, 2018

@Man-Jain you can politely ask the PR implementor to see if he can fix the PR comments otherwise you can fork his PR and try to fix it yourself if you are in a hurry.

@davidism
Copy link
Member

davidism commented Dec 1, 2018

The PR is fine, I just haven't got around to merging it.

@davidism davidism modified the milestones: 1.0.3, 1.1 Jan 7, 2019
@pallets pallets deleted a comment from ivonindza Feb 8, 2019
davidism added a commit that referenced this issue May 19, 2019
Fix #2926 `Default port overrides requesting a system assigned port`
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants