Skip to content

Conversation

@kelvinhammond
Copy link
Collaborator

@kelvinhammond kelvinhammond commented Oct 8, 2025

libzim 9.4.0 has been released, this is a work in progress

Diff: https://github.com/openzim/libzim/compare/9.3.0...9.4.0?diff=unified&w=#diff-b803fcb7f17ed9235f1e5cb1fcd2f5d3b2838429d4368ae4c57ce4436577f03f

Fixes Issues

Todos

Extra Todos

Trying to fix: Threading issues that have causes issues for the last few years. Try #whatever.

  • Remove the superfluous HandleScope that I but in places where it's not required. They should only be used, from my understanding, when we're creating JavaScript objects on the stack / heap and we want them removed as they aren't returned. Think for loop and modifying objects that aren't returned.
  • Try
    • We pass around Napi::External(env, **a_reference**) in a few places, is this actually safe, will the reference be handled immediately and are we copying the data fully before it is removed from the stack. Basically will javascript create our ObjectWrap immediately when we call it's constructor Napi::Function and in that constructor are we properly copying and not keeping reference to the Napi::External pointer.
      • The assumption is that since Javascript / Nodejs are single threaded event loops that it will call our code immediately but this is just an assumption, verify.
    • See: https://github.com/nodejs/node-addon-examples/blob/main/src/6-threadsafe-function/thread_safe_function_counting/node-addon-api/addon.cc
    • Moving from AsyncWorker to just a std::thread when adding Item Kept those
    • May need to Ref() from within the ObjectWrap'd object so it's not garbage collected then unref when destroying the thread safe function Wasn't needed
    • Implement TypedThreadSafeFunction references
  • Future
    • How does ObjectWrap handle copying?
    • Do we even need std::shared_ptr if we're not copying or passing the object around, could we just use an object. I think originally I thought we'd be passing around the values like entry more, verify this isn't the case.
      • In a few place we didn't and I removed those, still need to review others.
    • node-addon-api may already catch exception, check if it does and if these can caught by javascript. If so, remove the try catches we have all over the place. Confirmed, it does. I still added some more logging, it doesn't catch errors too well when it's an internal nodejs error :/

To break out into another ticket (issue)

@kelvinhammond kelvinhammond marked this pull request as draft October 8, 2025 23:23
@kelvinhammond kelvinhammond self-assigned this Oct 8, 2025
@kelvinhammond kelvinhammond changed the title Started Upgrade to libzim 9.4.0 (future) Upgrade to libzim 9.4.0 Oct 8, 2025
@kelvinhammond kelvinhammond marked this pull request as ready for review December 9, 2025 22:00
@kelvinhammond kelvinhammond marked this pull request as draft December 9, 2025 22:02
@kelson42 kelson42 requested review from benoit74 and Copilot and removed request for Copilot December 10, 2025 08:50
We don't really need a shared_ptr to Blob similar to why we don't need
one for std::string, it manages it's memory internally.
@benoit74 benoit74 removed their request for review December 10, 2025 21:53
Finally, went through all of the code line by line and
the node-addon-api examples.

Decided to go with the `TypedThreadSafeFunction` and make
some wrapper classes to separate the logic. I ran
`test/makeLargeZim.ts` quite a times and no crashes.

openzim#80

Added some extra logging, may not be required.
@kelvinhammond kelvinhammond marked this pull request as ready for review December 10, 2025 23:41
@kelvinhammond kelvinhammond requested review from benoit74, Copilot and kelson42 and removed request for benoit74 and Copilot December 11, 2025 00:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR upgrades node-libzim to use libzim version 9.4.0, introducing new functionality and making several architectural improvements including OpenConfig support, enhanced illustration handling with IllustrationInfo, global cluster cache management, and refactored thread-safe function implementations.

Key Changes:

  • Added OpenConfig class for configuring archive opening behavior
  • Introduced IllustrationInfo class for more detailed illustration metadata
  • Migrated cluster cache functions from archive-level to global scope
  • Refactored thread-safe function wrappers to use TypedThreadSafeFunction

Reviewed changes

Copilot reviewed 24 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/zim.test.ts Added tests for StringProvider, IllustrationInfo, OpenConfig, and updated cluster cache tests to use global functions
test/makeLargeZim.ts Updated to use modern imports and enabled custom item testing
src/writerItem.h Refactored to use TypedThreadSafeFunction wrappers and added static helper methods
src/suggestion.h Removed unnecessary HandleScope declarations
src/search.h Removed unnecessary HandleScope declarations
src/openconfig.h New file implementing OpenConfig class for archive configuration
src/module.cc Added initialization for OpenConfig and IllustrationInfo, plus global cluster cache functions
src/item.h Updated getDirectAccessInformation to return structured data with isValid field
src/index.js Exported new classes and global cluster cache functions
src/illustration.h New file implementing IllustrationInfo class for illustration metadata
src/entryrange.h File deleted (not shown in diffs)
src/entry.h Removed unnecessary HandleScope declaration
src/creator.h Enhanced addIllustration and addMetadata to support IllustrationInfo and multiple provider types
src/contentProvider.h Refactored to use TypedThreadSafeFunction with FeedTSFN wrapper and added move semantics
src/common.h Added new constructor references and removed unnecessary HandleScope declarations
src/blob.h Changed from shared_ptr to value semantics and added InstanceOf/GetConstructor methods
src/archive.h Added OpenConfig support, enhanced illustration methods, removed archive-level cluster cache functions
package.json Updated version to 4.0.0-dev0 and upgraded dependencies
download-libzim.js Replaced deprecated url.parse with URL constructor
bundle-libzim.js Fixed ARM64 architecture path
binding.gyp Updated ARM64 library paths
README.md Added local development documentation
.github/workflows/ci.yml Removed macos-13 from CI matrix
.env Updated LIBZIM_VERSION to 9.4.0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 26 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 26 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 146 to +180
Napi::Value getSize(const Napi::CallbackInfo &info) {
if (!provider_) {
throw Napi::Error::New(
info.Env(), "StringProvider has been moved and is no longer valid.");
}
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message incorrectly states that StringProvider 'has been moved', but the moved state is internal implementation detail. Consider rephrasing to 'StringProvider is in an invalid state' or 'StringProvider has already been consumed'.

Copilot uses AI. Check for mistakes.
Comment on lines 222 to +282
Napi::Value getSize(const Napi::CallbackInfo &info) {
if (!provider_) {
throw Napi::Error::New(
info.Env(), "FileProvider has been moved and is no longer valid.");
}
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message incorrectly states that FileProvider 'has been moved', but the moved state is internal implementation detail. Consider rephrasing to 'FileProvider is in an invalid state' or 'FileProvider has already been consumed'.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@benoit74 benoit74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, that's a good and huge PR!

Most of these code changes are well beyond my expertise ; nothing was hurting my eyes, so it is probably good to me.

I have one minor remark regarding CI, that's all for me.

I really hope the new FeedTSFN approach is going to work well, that would be a significant game changer.

@kelson42 kelson42 merged commit c114ca1 into openzim:main Dec 13, 2025
22 checks passed
@codecov
Copy link

codecov bot commented Dec 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (02c8fb7) to head (2ec85e8).
⚠️ Report is 29 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff     @@
##   main   #171   +/-   ##
===========================
===========================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

3 participants