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

Add SO_REUSEADDR option before binding to port #269

Merged
merged 2 commits into from
Mar 14, 2024

Conversation

elias-a
Copy link
Contributor

@elias-a elias-a commented Mar 10, 2024

No description provided.

@mwcraig
Copy link
Contributor

mwcraig commented Mar 11, 2024

Thanks for opening this @elias-a -- what problem is this fixing? I have top admit I'm not super familiar with the web socket pieces of vpython...

@elias-a
Copy link
Contributor Author

elias-a commented Mar 11, 2024

Hi @mwcraig, I ran into an issue with re-running a vpython script - after closing the browser or exiting the program via Ctrl-C, I’m not able to successfully run the script again for a few tens of seconds. The issue appears to be that the TCP connection remains open for a period TIME_WAIT, preventing a new connection from being made on the same port when I run the program again. Setting the SO_REUSEADDR option overrides this default behavior and allows a connection on the same port even while in the TIME_WAIT state. Here’s the traceback I get:
Traceback (most recent call last): File "/Users/elias-a/projects/vpython-test/run.py", line 4, in <module> box(length=1, height=1, width=1) File "/Users/elias-a/projects/vpython-test/venv/src/vpython/vpython/vpython.py", line 1183, in __init__ super(box, self).setup(args) File "/Users/elias-a/projects/vpython-test/venv/src/vpython/vpython/vpython.py", line 612, in setup super(standardAttributes, self).__init__() File "/Users/elias-a/projects/vpython-test/venv/src/vpython/vpython/vpython.py", line 267, in __init__ from .no_notebook import _ File "/Users/elias-a/projects/vpython-test/venv/src/vpython/vpython/no_notebook.py", line 66, in <module> __HTTP_PORT = find_free_port(4200) ^^^^^^^^^^^^^^^^^^^^ File "/Users/elias-a/projects/vpython-test/venv/src/vpython/vpython/no_notebook.py", line 63, in find_free_port s.bind(('', port)) OSError: [Errno 48] Address already in use Exception ignored in: <function standardAttributes.__del__ at 0x110149440> Traceback (most recent call last): File "/Users/elias-a/projects/vpython-test/venv/src/vpython/vpython/vpython.py", line 1176, in __del__ super(standardAttributes, self).__del__() File "/Users/elias-a/projects/vpython-test/venv/src/vpython/vpython/vpython.py", line 348, in __del__ cmd = {"cmd": "delete", "idx": self.idx} ^^^^^^^^ AttributeError: 'box' object has no attribute 'idx'

@mwcraig
Copy link
Contributor

mwcraig commented Mar 14, 2024

Thanks @elias-a -- could you please add yourself to the list of contributors at CONTRIBUTORS.md?

@elias-a
Copy link
Contributor Author

elias-a commented Mar 14, 2024

Done. Thanks @mwcraig

@mwcraig mwcraig merged commit 39969cc into vpython:master Mar 14, 2024
14 checks passed
@mwcraig
Copy link
Contributor

mwcraig commented Mar 14, 2024

Thanks, @elias-a!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants