Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNineteen committed Aug 17, 2023
1 parent dfe224a commit 02df369
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/gossip/active_set.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ pub const ActiveSet = struct {
errdefer active_set_endpoints.deinit();

// change to while loop
crds_table.read();
errdefer crds_table.release_read();

for (self.peers[0..self.len]) |peer_pubkey| {
const peer_info = crds_table.get(crds.CrdsValueLabel{
.LegacyContactInfo = peer_pubkey,
Expand All @@ -129,6 +132,7 @@ pub const ActiveSet = struct {
break;
}
}
crds_table.release_read();

return active_set_endpoints;
}
Expand Down
11 changes: 9 additions & 2 deletions src/gossip/gossip_service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ pub const GossipService = struct {
std.debug.assert(MAX_SIZE == nodes.len);

crds_table.read();
errdefer crds_table.release_read();
var buf: [MAX_SIZE]crds.CrdsVersionedValue = undefined;
const contact_infos = try crds_table.get_contact_infos(&buf);
crds_table.release_read();
Expand Down Expand Up @@ -489,7 +490,7 @@ pub const GossipService = struct {
push_msg_queue: *std.ArrayList(CrdsValue),
push_msg_queue_lock: *std.Thread.Mutex,
) !void {
const wallclock = get_wallclock();
const now = get_wallclock();

push_msg_queue_lock.lock();
defer push_msg_queue_lock.unlock();
Expand All @@ -498,7 +499,7 @@ pub const GossipService = struct {
defer crds_table.release_write();

while (push_msg_queue.popOrNull()) |crds_value| {
crds_table.insert(crds_value, wallclock) catch {};
crds_table.insert(crds_value, now) catch {};
}
}

Expand All @@ -513,6 +514,7 @@ pub const GossipService = struct {
// TODO: find a better static value?
var buf: [512]crds.CrdsVersionedValue = undefined;
crds_table.read();
errdefer crds_table.release_read();
var crds_entries = try crds_table.get_entries_with_cursor(&buf, push_cursor);
crds_table.release_read();

Expand All @@ -526,6 +528,7 @@ pub const GossipService = struct {
defer push_messages.deinit();

active_set_lock.lockShared();
errdefer active_set_lock.unlockShared();

var num_values_considered: usize = 0;
for (crds_entries) |entry| {
Expand Down Expand Up @@ -673,9 +676,13 @@ pub const GossipService = struct {
return std.ArrayList(Packet).init(allocator);
}

crds_table.read();
const from_contact_info = crds_table.get(crds.CrdsValueLabel{ .LegacyContactInfo = push_from }) orelse {
crds_table.release_read();
return error.CantFindContactInfo;
};
crds_table.release_read();

const from_gossip_addr = from_contact_info.value.data.LegacyContactInfo.gossip;
try crds.sanitize_socket(&from_gossip_addr);

Expand Down
3 changes: 2 additions & 1 deletion src/gossip/pull_request.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn build_crds_filters(
max_n_filters: usize,
) !ArrayList(CrdsFilter) {
crds_table.read();
defer crds_table.release_read();
errdefer crds_table.release_read(); // ensure lock is released even on errors

const num_items = crds_table.len() + crds_table.purged.len() + failed_pull_hashes.items.len;

Expand All @@ -54,6 +54,7 @@ pub fn build_crds_filters(
for (failed_pull_hashes.items) |hash| {
filter_set.add(&hash);
}
crds_table.release_read();

// note: filter set is deinit() in this fcn
const filters = try filter_set.consume_for_crds_filters(alloc, max_n_filters);
Expand Down

0 comments on commit 02df369

Please sign in to comment.