Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vmsdk/src/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
extern "C" { \
int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, \
int argc) { \
vmsdk::TrackCurrentAsMainThread(); \
if (auto status = vmsdk::module::OnLoad(ctx, argv, argc, options); \
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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, coding in the comment section without an IDE is hard. I thought status was absl::Status here for some reason. But yeah you get the idea

\
if (options.on_load.has_value()) { \
return vmsdk::module::OnLoadDone( \
Expand Down
Loading