@@ -966,14 +966,21 @@ pub const DNSResolver = struct {
966966
967967 const PendingCache = bun .HiveArray (GetAddrInfoRequest .PendingCacheKey , 32 );
968968
969+ fn getKey (this : * DNSResolver , index : u8 , comptime cache_name : []const u8 ) GetAddrInfoRequest.PendingCacheKey {
970+ var cache : * PendingCache = &@field (this , cache_name );
971+ std .debug .assert (! cache .available .isSet (index ));
972+ const entry = cache .buffer [index ];
973+ cache .buffer [index ] = undefined ;
974+
975+ var available = cache .available ;
976+ available .set (index );
977+ cache .available = available ;
978+
979+ return entry ;
980+ }
981+
969982 pub fn drainPendingHostCares (this : * DNSResolver , index : u8 , err : ? c_ares.Error , timeout : i32 , result : ? * c_ares.AddrInfo ) void {
970- const key : GetAddrInfoRequest.PendingCacheKey = brk : {
971- std .debug .assert (! this .pending_host_cache_cares .available .isSet (index ));
972- const entry = this .pending_host_cache_cares .buffer [index ];
973- this .pending_host_cache_cares .buffer [index ] = undefined ;
974- this .pending_host_cache_cares .available .unset (index );
975- break :brk entry ;
976- };
983+ const key = this .getKey (index , "pending_host_cache_cares" );
977984
978985 var addr = result orelse {
979986 var pending : ? * DNSLookup = key .lookup .head .next ;
@@ -1015,13 +1022,7 @@ pub const DNSResolver = struct {
10151022 }
10161023
10171024 pub fn drainPendingHostNative (this : * DNSResolver , index : u8 , globalObject : * JSC.JSGlobalObject , err : i32 , result : GetAddrInfo.Result.Any ) void {
1018- const key : GetAddrInfoRequest.PendingCacheKey = brk : {
1019- std .debug .assert (! this .pending_host_cache_native .available .isSet (index ));
1020- const entry = this .pending_host_cache_native .buffer [index ];
1021- this .pending_host_cache_native .buffer [index ] = undefined ;
1022- this .pending_host_cache_native .available .unset (index );
1023- break :brk entry ;
1024- };
1025+ const key = this .getKey (index , "pending_host_cache_native" );
10251026
10261027 var array = result .toJS (globalObject ) orelse {
10271028 var pending : ? * DNSLookup = key .lookup .head .next ;
0 commit comments