wavefnd / wavefnd/Wave

Stop guessing between HANDLE and SOCKET by trying CloseHandle first

Open
#568 0 comments 0 reactions 0 assignees View on GitHub
bug help wanted os-specific bug
Dominant language
Rust
Stars
53
Forks
16
Avg merge
4h 22m
Merged PRs (30d)
46

Description

The Windows filesystem `close(fd)` calls CloseHandle first and calls closesocket only if that fails. This is not a valid way to distinguish resource kinds: Microsoft explicitly requires sockets to be closed with closesocket. A successful CloseHandle probe can bypass Winsock cleanup, and invalid-handle probes can also raise debugger exceptions. The network provider already has a dedicated close_socket path.

This issue concerns choosing the correct close operation, not only preserving the error code after failure.

Code evidence:

- [std/sys/windows/fs.wave:137](https://github.com/wavefnd/Wave/blob/ea74c2dafc31da876e5561f2d176ba719f5a0458/std/sys/windows/fs.wave#L137)
- [std/sys/windows/socket.wave:137](https://github.com/wavefnd/Wave/blob/ea74c2dafc31da876e5561f2d176ba719f5a0458/std/sys/windows/socket.wave#L137)
- [std/net/socket_base.wave:359](https://github.com/wavefnd/Wave/blob/ea74c2dafc31da876e5561f2d176ba719f5a0458/std/net/socket_base.wave#L359)

Acceptance:

- [ ] Choose the close operation from the resource/API contract rather than invoking a destructive API as a type probe.
- [ ] Keep ordinary files, standard handles and Winsock sockets on the appropriate native close paths.
- [ ] If generic I/O close does not support sockets, make that boundary explicit; if it does, retain sufficient resource-kind information.
- [ ] Add native repeated-open/close and invalid-handle coverage, including checks that socket resources are released exactly once.

Reference: [CloseHandle socket restrictions](https://learn.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle). Related #385 and #523; the latter covers error translation, not unsafe resource-kind guessing.

Audit status: static source inspection against canonical master `ea74c2dafc31da876e5561f2d176ba719f5a0458` on 2026-09-10. No compiler build, test execution, implementation change or local reproduction was performed for this report. The examples describe the source-derived behavior to verify when implementing the fix.

Contributor guide

Open the contributing guide

Research direction

Read std/sys/windows/fs.wave:137 and std/sys/windows/socket.wave:137, then trace the generic I/O boundary through std/net/socket_base.wave:359. Verify how resource kinds are represented before choosing a native close path. Done means ordinary files, standard handles, and Winsock sockets use the correct operation, with repeated-open/close and invalid-handle coverage proving sockets are released exactly once.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.