Skip to content

[llvm][Support] Use ::closesocket for native sockets on Windows - #216

Closed
tagolog wants to merge 2 commits into
mainfrom
tagolog/socket-crash-on-windows
Closed

tagolog wants to merge 2 commits into
mainfrom
tagolog/socket-crash-on-windows

Conversation

@tagolog

@tagolog tagolog commented Sep 25, 2026

Copy link
Copy Markdown

Calling ::close on a Windows SOCKET that has not been converted with _open_osfhandle crashes and aborts the process with 0xC0000409 instead of returning an error.

Use ::closesocket on Windows for those sockets, and keep ::close on POSIX.

Calling ::close on a Windows SOCKET that has not been converted with _open_osfhandle crashes and aborts the process instead of returning an error.

Use ::closesocket on Windows for those sockets, and keep ::close on POSIX.
@github-actions

Copy link
Copy Markdown

Hello @tagolog 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.


Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.


If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you,
The LLVM Community

@slydiman

Copy link
Copy Markdown
Contributor

Consider define INVALID_SOCKET for Unix and unify the socket creation.

#ifdef _WIN32
using NativeSocket = SOCKET;
#else
using NativeSocket = int;
#define INVALID_SOCKET -1
#endif

and replace

#ifdef _WIN32
  WSABalancer _;
  SOCKET Socket = socket(AF_UNIX, SOCK_STREAM, 0);
  if (Socket == INVALID_SOCKET)
#else
  int Socket = socket(AF_UNIX, SOCK_STREAM, 0);
  if (Socket == -1)
#endif

with

#ifdef _WIN32
  WSABalancer _;
#endif // _WIN32
  NativeSocket Socket = socket(AF_UNIX, SOCK_STREAM, 0);
  if (Socket == INVALID_SOCKET)

…socket creation and the failure check are no longer duplicated
@tagolog

tagolog commented Oct 2, 2026

Copy link
Copy Markdown
Author

PR has been merged into the llvm/llvm-project
#226613 - [llvm][Support] Use ::closesocket for native sockets on Windows

@tagolog tagolog closed this Oct 2, 2026
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