diff --git a/src/Conn.cc b/src/Conn.cc index bf954f85c6..d1336803a7 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -195,7 +195,17 @@ const RecordValPtr& Connection::GetVal() { conn_val = make_intrusive(id::connection); auto id_val = make_intrusive(id::conn_id); - auto* ctx = id_val->GetFieldAs(5); + + constexpr int ctx_offset = 5; + + // If the conn_id_ctx type has no fields at all, set it to the singleton instance, + // otherwise the instance is initialized on first access through GetField() below. + if ( conn_id_ctx_singleton ) { + assert(id::conn_id_ctx->NumFields() == 0); + id_val->Assign(ctx_offset, conn_id_ctx_singleton); + } + + auto ctx = id_val->GetField(ctx_offset); // Allow customized ConnKeys to augment conn_id and ctx. key->PopulateConnIdVal(*id_val, *ctx);