@@ -658,8 +658,21 @@ func TestFdDialer_Dial(t *testing.T) {
658658 t .Run (tc .name , func (t * testing.T ) {
659659 sock , err := net .Dial ("tcp" , addr )
660660 require .NoError (t , err )
661+ defer sock .Close ()
662+
663+ // It seems that the file descriptor is not always fully ready
664+ // after the connection is created. These lines help avoid the
665+ // "bad file descriptor" errors.
666+ //
667+ // We already tried to use the SyscallConn(), but it has the same
668+ // issue.
669+ time .Sleep (time .Millisecond )
670+ sock .(* net.TCPConn ).SetLinger (0 )
671+
661672 f , err := sock .(* net.TCPConn ).File ()
662673 require .NoError (t , err )
674+ defer f .Close ()
675+
663676 dialer := tarantool.FdDialer {
664677 Fd : f .Fd (),
665678 }
@@ -676,8 +689,21 @@ func TestFdDialer_Dial_requirements(t *testing.T) {
676689
677690 sock , err := net .Dial ("tcp" , addr )
678691 require .NoError (t , err )
692+ defer sock .Close ()
693+
694+ // It seems that the file descriptor is not always fully ready after the
695+ // connection is created. These lines help avoid the
696+ // "bad file descriptor" errors.
697+ //
698+ // We already tried to use the SyscallConn(), but it has the same
699+ // issue.
700+ time .Sleep (time .Millisecond )
701+ sock .(* net.TCPConn ).SetLinger (0 )
702+
679703 f , err := sock .(* net.TCPConn ).File ()
680704 require .NoError (t , err )
705+ defer f .Close ()
706+
681707 dialer := tarantool.FdDialer {
682708 Fd : f .Fd (),
683709 RequiredProtocolInfo : tarantool.ProtocolInfo {
@@ -688,6 +714,7 @@ func TestFdDialer_Dial_requirements(t *testing.T) {
688714 testDialAccept (testDialOpts {}, l )
689715 ctx , cancel := test_helpers .GetConnectContext ()
690716 defer cancel ()
717+
691718 conn , err := dialer .Dial (ctx , tarantool.DialOpts {})
692719 if err == nil {
693720 conn .Close ()
0 commit comments