Commit d6daa582 authored by sevenuz's avatar sevenuz
Browse files

client: register the provider-0 variant of every RPC at engine setup

thallium's rpc.on(endpoint) forwards with provider id 0. Margo registers
that provider variant lazily inside the first forward
(margo_provider_iforward_internal: HG_Registered, then register) without
a lock. Concurrent first forwards from several FUSE threads register it
twice ('Overwriting RPC callback/data'), and a handle of another thread
then fails with 'HG_Forward() Could not get proc info' / HG_FAULT. This
is the cause of MN5 bug 4 (short reads / EOF prematurely, EBUSY writes),
and every additional RPC engine opens the window once more per tag.

add_rpc_engine now registers the provider-0 variant of every
pre-defined tag with the procs of the base registration, while the
client is still single-threaded.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VotrDxGfCTADQU5bfhXBjD
parent 12ed1aa1
Loading
Loading
Loading
Loading
Loading
+27 −1
Changes for src/client/preload_context.cpp: 27 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -839,8 +839,34 @@ void
PreloadContext::add_rpc_engine(std::shared_ptr<thallium::engine> engine,
                               const std::vector<const char*>& tags) {
    std::unordered_map<std::string, thallium::remote_procedure> procs;
    margo_instance_id mid = engine->get_margo_instance();
    hg_class_t* hg_class = margo_get_class(mid);
    for(const auto* tag : tags) {
        procs.emplace(tag, engine->define(tag));
        auto proc = engine->define(tag);
        // thallium's rpc.on(endpoint) forwards with provider id 0. Margo
        // registers that provider variant of the RPC lazily in the first
        // forward (margo_provider_iforward_internal: HG_Registered, then
        // register), without a lock: concurrent first forwards from several
        // threads register it twice ("Overwriting RPC callback/data"), and a
        // handle of another thread then fails with "HG_Forward() Could not get
        // proc info" / HG_FAULT (MN5 bug 4: short reads in the FUSE client,
        // more frequent with several engines). Register it here, while still
        // single-threaded, with the procs of the base registration.
        hg_bool_t registered = HG_FALSE;
        hg_proc_cb_t in_cb = nullptr;
        hg_proc_cb_t out_cb = nullptr;
        hg_id_t provider_rpc_id = 0;
        hg_bool_t provider_registered = HG_FALSE;
        if(HG_Registered_proc_cb(hg_class, proc.id(), &registered, &in_cb,
                                 &out_cb) == HG_SUCCESS &&
           registered &&
           margo_provider_registered_name(mid, tag, 0, &provider_rpc_id,
                                          &provider_registered) == HG_SUCCESS &&
           !provider_registered) {
            margo_provider_register_name(mid, tag, in_cb, out_cb, nullptr, 0,
                                         ABT_POOL_NULL);
        }
        procs.emplace(tag, std::move(proc));
    }
    rpc_engines_.push_back(std::move(engine));
    rpc_procs_.push_back(std::move(procs));