Skip to content

Conversation

dmitrypol
Copy link

@dmitrypol dmitrypol commented Oct 14, 2025

addresses #372
I tested this on Valkey 8 and 9
@murphyjacob4 - I implemented the change per your recommendation.

Signed-off-by: Dmitry Polyakovsky <dmitrypol@gmail.com>
@murphyjacob4
Copy link
Collaborator

murphyjacob4 commented Oct 15, 2025

For context - @dmitrypol and I debugged - the problem is when you load two instances of the module, they will actually read from the same symbols and cause initialization problems. It surfaces as a problem here because the static main thread variable must be unset (but it set by the other shared object).

status != VALKEYMODULE_OK) { \
return status; \
} \
vmsdk::TrackCurrentAsMainThread(); \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it's worth having a "symbol collision" condition that we check prior to calling OnLoad? I guess it is nice if we can keep the main thread tracking before the OnLoad call, so that OnLoad will have it set.

So something like:

absl::Status verifyLoadedOnlyOnce() {
    static bool prev_loaded = false;
    if (prev_loaded) return absl::FailedPrecondition("The module is already loaded");
    prev_loaded = true;
    return absl::OkStatus();
}
...
  int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv,  \
                          int argc) {                                       \
    VMSDK_RETURN_IF_ERROR(verifyLoadedOnlyOnce()); \
    ... <existing code>

Copy link
Member

Choose a reason for hiding this comment

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

well, don't use absl::Status as the return type, use a boolean. Don't use VMSDK_RETURN_IF_ERROR.
Put a message in the log directly using a static string (no memory allocations ,please). Then return VALKEYMODULE_ERROR if it fails.

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.

3 participants