Skip to content

Windows: _get_osfhandle asserts in debug mode when given a socket #19722

Closed

Description

@dktapps

handles[n_handles] = (HANDLE)(uintptr_t)_get_osfhandle(i);

When calling stream_select() with a stream socket, this will assert in debug binaries, which makes it inconvenient to test some applications.

I'm not sure what could be done to address this. There doesn't seem to be an easy way to ask the CRT if the fd is a file resource.

According to ChatGPT getsockopt() and checking for WSAENOTSOCK might be a better way to check for sockets, but I haven't tried this myself.
Hoping someone with more expertise about the depths of Windows can suggest something.

Activity

  1. devnexen commented on Sep 5, 2025

    @devnexen
    Member

    Hi @dktapps sorry to hijack your ticket, seems you seem to know well windows, if I m not asking too much, would you mind having a look there ? Cheers.

  2. added a commit that references this issue on Sep 5, 2025
  3. added a commit that references this issue on Sep 10, 2025
    36057b9
  4. added 4 commits that reference this issue on Oct 15, 2025
    94625a0
    8dd117f
    0ef96a2
    8dc1a3d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions