Skip to content

Commit c4eeef2

Browse files
committed
On CDP process error, let client decide how to close
Fixes issue where CDP closes the client, but client still registers a recv operation.
1 parent b60a91f commit c4eeef2

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/cdp/cdp.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ pub const CDP = struct {
114114
self.session = try self.browser.newSession(self);
115115
}
116116

117-
pub fn processMessage(self: *CDP, msg: []const u8) void {
117+
pub fn processMessage(self: *CDP, msg: []const u8) bool {
118118
const arena = &self.message_arena;
119119
defer _ = arena.reset(.{ .retain_with_limit = 1024 * 16 });
120120

121121
self.dispatch(arena.allocator(), self, msg) catch |err| {
122122
log.err("failed to process message: {}\n{s}", .{ err, msg });
123-
self.client.close(null);
124-
return;
123+
return false;
125124
};
125+
return true;
126126
}
127127

128128
// Called from above, in processMessage which handles client messages

src/server.zig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ fn ClientT(comptime S: type, comptime C: type) type {
555555
errdefer self.server.queueClose(self.socket);
556556

557557
var reader = &self.reader;
558+
558559
while (true) {
559560
const msg = reader.next() catch |err| {
560561
switch (err) {
@@ -578,7 +579,10 @@ fn ClientT(comptime S: type, comptime C: type) type {
578579
self.server.queueClose(self.socket);
579580
return false;
580581
},
581-
.text, .binary => self.cdp.?.processMessage(msg.data),
582+
.text, .binary => if (self.cdp.?.processMessage(msg.data) == false) {
583+
self.close(null);
584+
return false;
585+
},
582586
}
583587
if (msg.cleanup_fragment) {
584588
reader.cleanup();

0 commit comments

Comments
 (0)