Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Linux with epoll, passing a regular file to
hio_read()returns0, even though epoll refused to watch it withEPERM. The caller can wait for a read callback that will never arrive. If libhv already has bytes buffered, the same failed call can even deliver those bytes immediately, making the read appear to have started.What goes wrong
hio_read()askshio_add()to watch the descriptor for reads.hio_add()returns an error and leaves the read bit clear.hio_read()ignores that error, processes any buffered bytes, and returns success. The higher-levelhread()also returns an I/O handle.There is a second case when a socket already has a working read callback. If the caller asks to add write interest with a different callback,
hio_add()replaces the callback before the kernel accepts the new interest. If the kernel rejects the change, the next ordinary read can run the replacement callback even though the upgrade failed.What changes
Read startup now checks registration before installing the requested read mode, callback or buffer. A failed
hio_read()returns-1. Thehread(),hrecv()andhrecvfrom()helpers returnNULL. The handle stays open and buffered data stays available for another read. A successful read can still deliver buffered bytes immediately. A failed interest upgrade keeps the original callback and interest mask.The loop also checks registration of its own wake reader. If registration fails, it cleans up the wake descriptors and reports startup failure. A caller that owns the loop can retry.
Regression tests
The Linux test uses a regular file for the real epoll refusal. It also starts a read watch on a socket pair, injects one failed interest change, then sends a byte and verifies that the original callback receives it. Other checks cover buffered reads, failed one-shot and framed reads, and loop startup after one failed wake registration.
The test fails on unmodified master with
regular file read reported success. It passes in Linux Debug with the shared library and Release with the static library. The existinghdns_testandtcpclient_dns_testalso pass in both builds. The regression passed with each Linux wake transport (eventfd, pipe and socket pair) and with the Makefile build.Run the focused test with CMake.
cmake -S . -B build -DBUILD_UNITTEST=ON -DBUILD_EXAMPLES=OFF cmake --build build --target read_registration_test ./build/bin/read_registration_test