File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -213,6 +213,10 @@ class DNSInstance {
213213 this . #records. set ( origin . hostname , records )
214214 }
215215
216+ deleteRecords ( origin ) {
217+ this . #records. delete ( origin . hostname )
218+ }
219+
216220 getHandler ( meta , opts ) {
217221 return new DNSDispatchHandler ( this , meta , opts )
218222 }
@@ -261,7 +265,7 @@ class DNSDispatchHandler extends DecoratorHandler {
261265 break
262266 }
263267 case 'ENOTFOUND' :
264- this . #state. deleteRecord ( this . #origin)
268+ this . #state. deleteRecords ( this . #origin)
265269 // eslint-disable-next-line no-fallthrough
266270 default :
267271 super . onResponseError ( controller , err )
Original file line number Diff line number Diff line change @@ -1732,6 +1732,57 @@ test('Should handle max cached items', async t => {
17321732 t . equal ( await response3 . body . text ( ) , 'hello world! (x2)' )
17331733} )
17341734
1735+ test ( 'Should handle ENOTFOUND response error' , async t => {
1736+ t = tspl ( t , { plan : 3 } )
1737+ let lookupCounter = 0
1738+
1739+ const requestOptions = {
1740+ method : 'GET' ,
1741+ path : '/' ,
1742+ origin : 'http://localhost'
1743+ }
1744+
1745+ const client = new Agent ( ) . compose ( [
1746+ dns ( {
1747+ lookup ( origin , opts , cb ) {
1748+ lookupCounter ++
1749+ if ( lookupCounter === 1 ) {
1750+ const err = new Error ( 'test error' )
1751+ err . code = 'ENOTFOUND'
1752+ cb ( err )
1753+ } else {
1754+ // Causes InformationalError
1755+ cb ( null , [ ] )
1756+ }
1757+ }
1758+ } )
1759+ ] )
1760+
1761+ after ( async ( ) => {
1762+ await client . close ( )
1763+ } )
1764+
1765+ let error1
1766+ try {
1767+ await client . request ( requestOptions )
1768+ } catch ( err ) {
1769+ error1 = err
1770+ }
1771+ t . equal ( error1 . code , 'ENOTFOUND' )
1772+
1773+ // Test that the records in the dns interceptor were deleted after the
1774+ // previous request
1775+ let error2
1776+ try {
1777+ await client . request ( requestOptions )
1778+ } catch ( err ) {
1779+ error2 = err
1780+ }
1781+ t . equal ( error2 . name , 'InformationalError' )
1782+
1783+ t . equal ( lookupCounter , 2 )
1784+ } )
1785+
17351786test ( '#3937 - Handle host correctly' , async t => {
17361787 t = tspl ( t , { plan : 10 } )
17371788
You can’t perform that action at this time.
0 commit comments