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

Crash when creating context with occupied port #14

Closed
fuzzybro-otoy opened this issue Oct 21, 2013 · 3 comments
Closed

Crash when creating context with occupied port #14

fuzzybro-otoy opened this issue Oct 21, 2013 · 3 comments

Comments

@fuzzybro-otoy
Copy link

libwebsocket_create_context(...) crashes on a line 2163 of libwebsockets.c while trying to create a context for a port that is taken by the other instance of libwebsockets (i.e. an instance of websocket server with a port 9000 is running in a separate process and I'm trying to create a new websocket server on the very same port)

if (n < 0) {
lwsl_err("ERROR on binding to port %d (%d %d)\n",
info->port, n, errno);
close(sockfd); // this line leads to the crash
goto bail;
}

commenting out the "close(sockfd);" line seems to solve the issue so libwebsocket_create_context is able to return NULL if a particular port is taken, but I don't think it's a proper way to solve this.

@fuzzybro-otoy
Copy link
Author

Forgot to mention:
Running this case on Windows 7 x64

@warmcat
Copy link
Collaborator

warmcat commented Oct 21, 2013

On 21/10/13 23:07, the mail apparently from fuzzy included:

libwebsocket_create_context(...) crashes on a line 2163 of
libwebsockets.c while trying to create a context for a port that is
taken by the other instance of libwebsockets (i.e. an instance of
websocket server with a port 9000 is running in a separate process and
I'm trying to create a new websocket server on the very same port)

if (n < 0) {
lwsl_err("ERROR on binding to port %d (%d %d)\n",
info->port, n, errno);
close(sockfd); // this line leads to the crash
goto bail;
}

commenting out the "close(sockfd);" line seems to solve the issue so
libwebsocket_create_context is able to return NULL if a particular port
is taken, but I don't think it's a proper way to solve this.

It's a Windows quirk unlike normal unixish OSes socket handles are not
file handles, you have to close them with closesocket(). We have
compatible_close() for this, I changed that and another example in the
same function to use it, that should solve your problem without
generating any new ones.

-Andy


Reply to this email directly or view it on GitHub
#14.

@fuzzybro-otoy
Copy link
Author

Great, thank you much!

@warmcat warmcat closed this as completed Oct 13, 2015
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

No branches or pull requests

1 participant