cdp: make Network.enable idempotent#3038
Closed
Ppsoft1991 wants to merge 1 commit into
Closed
Conversation
Avoid registering the same BrowserContext notification callbacks more than once. Duplicate registrations emit duplicate Network events and append every response body chunk repeatedly.
Collaborator
|
I think I'd rather dedupe in notification. We currently have no case where a receiver should add multiple listeners to an event (and I can't imagine ever needing it): pub fn register(self: *Notification, comptime event: EventType, receiver: anytype, func: EventFunc(event)) !void {
const allocator = self.allocator;
const gop = try self.listeners.getOrPut(allocator, @intFromPtr(receiver));
if (gop.found_existing) {
for (gop.value_ptr.items) |existing| {
if (existing.event == event) {
lp.assert(@as(*const anyopaque, @ptrCast(func)) == existing.func, "different notification callbacks per receiver", .{.event = event});
return;
}
}
} else {
gop.value_ptr.* = .empty;
}
var list = &@field(self.event_listeners, @tagName(event));
var listener = try self.mem_pool.create();
errdefer self.mem_pool.destroy(listener);
listener.* = .{
.node = .{},
.list = list,
.receiver = receiver,
.event = event,
.func = @ptrCast(func),
.struct_name = @typeName(@typeInfo(@TypeOf(receiver)).pointer.child),
};
try gop.value_ptr.append(allocator, listener);
// we don't add this until we've successfully added the entry to
// self.listeners
list.append(&listener.node);
}(would be nice to add a test for this too). Can remove the existing If you agree and prefer, you can close this and I'll make the change. |
Contributor
Author
|
I agree with your approach. Deduplicating in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Network.enableidempotent per browser contextNetwork.disablerunsRoot cause
Notification.registerappends a listener on every call. CallingNetwork.enabletwice therefore registers the samehttp_response_datacallback twice, andonHttpResponseDataappends every chunk twice tocaptured_responses.This is independent of #3037, which covers Network event payload completeness and worker request propagation.
Reproduction
Without this fix, the new test receives:
instead of the fixture body once.
Testing
mainTEST_FILTER='cdp.Network' ... zig build ... test: 9/9 passedzig fmt --checkgit diff --check