authorgravatar for bblack@wikimedia.orgBrandon Black <bblack@wikimedia.org> 2026-05-05 11:07:15-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-10 20:33:08+02:00
logd4f3881bdbdeea7b4ec4974da77acbc3f462328c
treea02113de0248f81e6798ee785b49d92078e50a2b
parenta6c2839505c9214ca6cd8baaa52e67fcf99c9e2e

std.Io.Threaded.lookupDns: use sendTimeout

Mostly I did this to test sendTimeout with something other than my own code. Now that send is Operation-based, it can also honor the timeout deadlines lookupDns is already enforcing on the receive side (which may matter if the socket output buffer gets filled - sends are not always immediately-successful!).

1 files changed, 15 insertions(+), 11 deletions(-)

lib/std/Io/Threaded.zig+15-11
...@@ -14655,6 +14655,11 @@ fn lookupDns(...@@ -14655,6 +14655,11 @@ fn lookupDns(
14655 };14655 };
1465614656
14657 send: while (now_ts.nanoseconds < final_ts.nanoseconds) : (now_ts = clock.now(t_io)) {14657 send: while (now_ts.nanoseconds < final_ts.nanoseconds) : (now_ts = clock.now(t_io)) {
14658 const timeout: Io.Timeout = .{ .deadline = .{
14659 .raw = now_ts.addDuration(attempt_duration),
14660 .clock = clock,
14661 } };
14662
14658 const max_messages = queries_buffer.len * HostName.ResolvConf.max_nameservers;14663 const max_messages = queries_buffer.len * HostName.ResolvConf.max_nameservers;
14659 {14664 {
14660 var message_buffer: [max_messages]net.OutgoingMessage = undefined;14665 var message_buffer: [max_messages]net.OutgoingMessage = undefined;
...@@ -14670,14 +14675,14 @@ fn lookupDns(...@@ -14670,14 +14675,14 @@ fn lookupDns(
14670 message_i += 1;14675 message_i += 1;
14671 }14676 }
14672 }14677 }
14673 _ = netSendPosix(t, socket.handle, message_buffer[0..message_i], .{}, false);14678 const send_err, _ = socket.sendManyTimeout(t_io, message_buffer[0..message_i], .{}, timeout);
14679 if (send_err) |err| switch (err) {
14680 error.Canceled => |e| return e,
14681 error.Timeout => continue :send,
14682 else => {},
14683 };
14674 }14684 }
1467514685
14676 const timeout: Io.Timeout = .{ .deadline = .{
14677 .raw = now_ts.addDuration(attempt_duration),
14678 .clock = clock,
14679 } };
14680
14681 while (true) {14686 while (true) {
14682 var message_buffer: [max_messages]net.IncomingMessage = @splat(.init);14687 var message_buffer: [max_messages]net.IncomingMessage = @splat(.init);
14683 const buf = answer_buffer[answer_buffer_i..];14688 const buf = answer_buffer[answer_buffer_i..];
...@@ -14713,12 +14718,11 @@ fn lookupDns(...@@ -14713,12 +14718,11 @@ fn lookupDns(
14713 if (answers_remaining == 0) break :send;14718 if (answers_remaining == 0) break :send;
14714 },14719 },
14715 2 => {14720 2 => {
14716 var retry_message: net.OutgoingMessage = .{14721 socket.sendTimeout(t_io, ns, query, timeout) catch |err| switch (err) {
14717 .address = ns,14722 error.Canceled => |e| return e,
14718 .data_ptr = query.ptr,14723 error.Timeout => continue :send,
14719 .data_len = query.len,14724 else => {},
14720 };14725 };
14721 _ = netSendPosix(t, socket.handle, (&retry_message)[0..1], .{}, false);
14722 continue;14726 continue;
14723 },14727 },
14724 else => continue,14728 else => continue,