Skip to content

fix: empty Buffer for 0-byte reads, real CephError from normalize() - #13

Merged
AlexanderSlaa merged 2 commits into
mainfrom
fix/zero-length-read-and-normalize
Nov 21, 2026
Merged

AlexanderSlaa merged 2 commits into
mainfrom
fix/zero-length-read-and-normalize

Conversation

@AlexanderSlaa

Copy link
Copy Markdown
Contributor

What and why

Fixes #8 and #9, one commit each.

#8: IoContext.read(oid, 0n) failed with ERANGE. The OSD treats a length of 0 as "read to the end of the object", which doesn't fit the empty buffer. A read of 0 bytes now checks that the object exists with rados_stat instead of reading it:

  • it resolves with an empty Buffer;
  • a missing object still fails with ENOENT, so a 0-byte read can't hide a missing object.

RbdImage.read(offset, 0n) already returned an empty Buffer and is unchanged.

#9: CephError.normalize() returned error-like objects unchanged. CephError[Symbol.hasInstance] matches any object with a numeric code and a string operation, so the instanceof check at the top of normalize() always returned early. It now checks the real prototype chain:

  • an error-like object becomes a CephError, with errno taken from code and the original kept as cause;
  • a real CephError is still returned unchanged.

normalize() isn't used inside the library, so only callers of the public method see the difference.

How it was tested

The new tests ran against both trees in the test cluster (Ceph Squid 19.2.7):

Test main this branch
integration: a read of 0 bytes returns an empty Buffer, or ENOENT for a missing object ✖ ✔
unit: normalize() turns error-like objects into a CephError and keeps real ones ✖ ✔

On the branch the full suite passes (15/15), with no build warnings, and the coverage check passes (rados_stat was already listed).

Checklist

  • npm run check, npm test (with the integration suite) and npm run coverage:api pass
  • New behaviour has a test; a bug fix has a test that fails without the fix
  • New librados/librbd symbols are classified in coverage/api.json (none new)
  • Operations on an IoContext use in_flight(state_)
  • README updated for user-visible changes (not needed)
  • Breaking changes are marked with ! in the title (none)

🤖 Generated with Claude Code

A.P.A. Slaa and others added 2 commits November 21, 2026 23:30
The OSD reads to the end of the object for a length of 0, which does not
fit the empty buffer, so librados failed the read with ERANGE. A read of
0 bytes now only checks that the object exists with rados_stat: it
resolves with an empty Buffer, and still fails with ENOENT for a missing
object.

Fixes #8

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CephError[Symbol.hasInstance] matches any object with a numeric code and
a string operation, so normalize() returned such objects unchanged and
its errno fallback never ran. It now checks the prototype chain, so an
error-like object becomes a CephError with errno filled in from code and
the original as its cause, while a real CephError is still returned as is.

Fixes #9

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlexanderSlaa
AlexanderSlaa merged commit c1895fb into main Nov 21, 2026
13 checks passed
@AlexanderSlaa
AlexanderSlaa deleted the fix/zero-length-read-and-normalize branch November 21, 2026 22:34
github-actions Bot pushed a commit that referenced this pull request Nov 21, 2026
## [1.2.2](v1.2.1...v1.2.2) (2026-11-21)

### Bug Fixes

* empty Buffer for 0-byte reads, real CephError from normalize() ([#13](#13)) ([c1895fb](c1895fb)), closes [#8](#8) [#9](#9)
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IoContext.read(oid, 0n) fails with ERANGE instead of returning an empty Buffer

1 participant