Skip to content

0.23.1: a handle is retired before its descriptor is closed; one release closes; a released handle's stream is no stream - #47

Merged
Sunrisepeak merged 1 commit into
mainfrom
fix/retire-before-close
Nov 12, 2026
Merged

Sunrisepeak merged 1 commit into
mainfrom
fix/retire-before-close

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

The construction openkal-linux#53 reports is this implementation's too: kal_net_close, kal_net_close_listener and kal_datagram_close closed the descriptor and then retired the handle, so a file or a connection another context opened between the two took the number with the old generation and was left with a stale handle; its stream was answered as zero, standard input.

  • Every release is okm::release, which retires and then closes (src/handle.h).
  • The generation is advanced by a compare-and-exchange from the value the handle carries: one release closes, a second closes nothing. It is read through the atomic operations.
  • kal_fs_stream and kal_net_stream answer a handle that names no live descriptor with a word no descriptor has; a transfer upon it reports kal_err_invalid.
  • tests/a_released_handle_is_stale_before_its_number_is_free.cpp: one context accepts and closes connections, one connects and closes, one opens, reads and closes a file; every read returns the file. On openkal-linux the same test finds 94 stale files in 3.4 million opens without the change, none with it.

…ase closes; a released handle's stream is no stream
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.

1 participant