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

Fix e race problem when starting server with port 0 (issue 362) #449

Closed
wants to merge 1 commit into from

Conversation

PerBothner
Copy link

I'm starting the server with a port of 0, so I can then immediately
open a client of the server, without hard-wiring in a specific
port. Before I start the client, I need to call getPort(). But that
may not work, since the server field may not have been set yet, and
that happens in a separate thread. My suggestion is to move the
initial socket.bind to the start method, before the run method in the
new thread.

I'm starting the server with a port of 0, so I can then immediately
open a client of the server, without hard-wiring in a specific
port. Before I start the client, I need to call getPort(). But that
may not work, since the server field may not have been set yet, and
that happens in a separate thread. My suggestion is to move the
initial socket.bind to the start method, before the run method in the
new thread.
@PerBothner
Copy link
Author

See issue #362 .

@marci4
Copy link
Collaborator

marci4 commented Apr 26, 2017

Hello @PerBothner
thinking about your pull request again.

Would it also just be sufficient for you to get a notification that the server startet up successfully?

Greetings
marci4

@PerBothner
Copy link
Author

No, because if the requested port number is zero, I also need to know the actual port number.

Note I am no longer using Java-WebSocket (I'm using libwebsockets instead), so this is no longer an issue for me or my projects.

@PerBothner
Copy link
Author

I may have misunderstood the question: The problem is solved if I can reliably get the actual port number after start-up.

(However, I'm still sticking with libwebsockets. Glad to see this project is alive again, though.)

@marci4 marci4 closed this Nov 5, 2017
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