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(
1465514655 };
1465614656
1465714657 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
1465814663 const max_messages = queries_buffer.len * HostName.ResolvConf.max_nameservers;
1465914664 {
1466014665 var message_buffer: [max_messages]net.OutgoingMessage = undefined;
......@@ -14670,14 +14675,14 @@ fn lookupDns(
1467014675 message_i += 1;
1467114676 }
1467214677 }
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 };
1467414684 }
1467514685
14676 const timeout: Io.Timeout = .{ .deadline = .{
14677 .raw = now_ts.addDuration(attempt_duration),
14678 .clock = clock,
14679 } };
14680
1468114686 while (true) {
1468214687 var message_buffer: [max_messages]net.IncomingMessage = @splat(.init);
1468314688 const buf = answer_buffer[answer_buffer_i..];
......@@ -14713,12 +14718,11 @@ fn lookupDns(
1471314718 if (answers_remaining == 0) break :send;
1471414719 },
1471514720 2 => {
14716 var retry_message: net.OutgoingMessage = .{
14717 .address = ns,
14718 .data_ptr = query.ptr,
14719 .data_len = query.len,
14721 socket.sendTimeout(t_io, ns, query, timeout) catch |err| switch (err) {
14722 error.Canceled => |e| return e,
14723 error.Timeout => continue :send,
14724 else => {},
1472014725 };
14721 _ = netSendPosix(t, socket.handle, (&retry_message)[0..1], .{}, false);
1472214726 continue;
1472314727 },
1472414728 else => continue,