@@ -317,7 +317,7 @@ func makeHTTPRequest(ctx context.Context, t *testing.T, podName string, port int
317317 scheme = "https"
318318 }
319319
320- url := fmt .Sprintf ("%s://localhost :%d%s" , scheme , localPort , path )
320+ url := fmt .Sprintf ("%s://127.0.0.1 :%d%s" , scheme , localPort , path )
321321 req , err := http .NewRequest ("GET" , url , nil )
322322 if err != nil {
323323 return nil , fmt .Errorf ("failed to create request: %w" , err )
@@ -354,7 +354,7 @@ func makeHTTPRequestToPort(ctx context.Context, t *testing.T, port int, path str
354354 scheme = "https"
355355 }
356356
357- url := fmt .Sprintf ("%s://localhost :%d%s" , scheme , port , path )
357+ url := fmt .Sprintf ("%s://127.0.0.1 :%d%s" , scheme , port , path )
358358 req , err := http .NewRequest ("GET" , url , nil )
359359 if err != nil {
360360 return nil , fmt .Errorf ("failed to create request: %w" , err )
@@ -419,35 +419,46 @@ func setupPortForward(_ context.Context, t *testing.T, podName string, remotePor
419419
420420 go func () {
421421 defer close (errCh )
422- defer func () {
423- if r := recover (); r != nil {
424- errCh <- fmt .Errorf ("port forwarding panic: %v" , r )
425- }
426- }()
427422
428423 pf , err := portforward .New (dialer , []string {fmt .Sprintf ("0:%d" , remotePort )}, stopCh , readyCh , io .Discard , io .Discard )
429424 if err != nil {
430- errCh <- fmt .Errorf ("port forward init failed: %w" , err )
425+ select {
426+ case errCh <- fmt .Errorf ("port forward init failed: %w" , err ):
427+ case <- stopCh :
428+ // Channel closed, ignore
429+ }
431430 return
432431 }
433432
434433 go func () {
435434 if err := pf .ForwardPorts (); err != nil {
436435 if ! strings .Contains (err .Error (), "connection reset" ) &&
437436 ! strings .Contains (err .Error (), "use of closed network connection" ) {
438- errCh <- fmt .Errorf ("port forward error: %w" , err )
437+ select {
438+ case errCh <- fmt .Errorf ("port forward error: %w" , err ):
439+ case <- stopCh :
440+ // Channel closed, ignore
441+ }
439442 }
440443 }
441444 }()
442445
443446 <- readyCh
444447 ports , err := pf .GetPorts ()
445448 if err != nil {
446- errCh <- fmt .Errorf ("failed to get forwarded ports: %w" , err )
449+ select {
450+ case errCh <- fmt .Errorf ("failed to get forwarded ports: %w" , err ):
451+ case <- stopCh :
452+ // Channel closed, ignore
453+ }
447454 return
448455 }
449456 if len (ports ) == 0 {
450- errCh <- fmt .Errorf ("no ports returned from port forwarder" )
457+ select {
458+ case errCh <- fmt .Errorf ("no ports returned from port forwarder" ):
459+ case <- stopCh :
460+ // Channel closed, ignore
461+ }
451462 return
452463 }
453464
@@ -510,7 +521,7 @@ func ptrInt64(v int64) *int64 {
510521}
511522
512523func extractServerCertificate (port int ) (* x509.CertPool , error ) {
513- conn , err := tls .Dial ("tcp" , fmt .Sprintf ("localhost :%d" , port ), & tls.Config {InsecureSkipVerify : true })
524+ conn , err := tls .Dial ("tcp" , fmt .Sprintf ("127.0.0.1 :%d" , port ), & tls.Config {InsecureSkipVerify : true })
514525 if err != nil {
515526 return nil , fmt .Errorf ("TLS dial failed: %w" , err )
516527 }
0 commit comments