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
Closed

Default port overrides requesting a system assigned port #2926

Ben-RK opened this issue Sep 28, 2018 · 8 comments
Milestone

Comments

@Ben-RK
Copy link

@Ben-RK 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

@davidism davidism commented Sep 28, 2018

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

Loading

@vorelq
Copy link
Contributor

@vorelq vorelq commented Sep 28, 2018

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

Loading

@patiencedaur
Copy link

@patiencedaur patiencedaur commented Oct 13, 2018

I think it's closed, it shows expected behavior

Loading

@Man-Jain
Copy link

@Man-Jain Man-Jain commented Nov 5, 2018

Is this one still up for grabs ?

Loading

@ThiefMaster
Copy link
Member

@ThiefMaster ThiefMaster commented Nov 5, 2018

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

Loading

@Man-Jain
Copy link

@Man-Jain Man-Jain commented Nov 5, 2018

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

Loading

@theodesp
Copy link

@theodesp 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.

Loading

@davidism
Copy link
Member

@davidism davidism commented Dec 1, 2018

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

Loading

@davidism davidism removed this from the 1.0.3 milestone Jan 7, 2019
@davidism davidism added this to the 1.1 milestone 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
Linked pull requests

Successfully merging a pull request may close this issue.

8 participants