diff --git a/src/lua/bsdsocket.lua b/src/lua/bsdsocket.lua
index 0b705fee46921b71b1718c71ea60704c79e97138..b3c3003ee6f90a57bb8a45b0396efdc89cbfba09 100644
--- a/src/lua/bsdsocket.lua
+++ b/src/lua/bsdsocket.lua
@@ -958,11 +958,7 @@ local function tcp_connect(host, port, timeout)
     local stop = box.time() + timeout
     local dns = getaddrinfo(host, port, timeout, { type = 'SOCK_STREAM',
         protocol = 'tcp' })
-    if dns == nil then
-        return nil
-    end
-
-    if #dns == 0 then
+    if dns == nil or #dns == 0 then
         box.errno(box.errno.EINVAL)
         return nil
     end
@@ -977,6 +973,7 @@ local function tcp_connect(host, port, timeout)
             return s
         end
     end
+    -- errno is set by tcp_connect_remote()
     return nil
 end
 
diff --git a/test/box/bsdsocket.result b/test/box/bsdsocket.result
index b9c13042077de8644b1de954dc3ddad90763a1e8..d3ad14f9aa68c65d8a4a37b584860b0032624160 100644
--- a/test/box/bsdsocket.result
+++ b/test/box/bsdsocket.result
@@ -1251,6 +1251,10 @@ lua s:close()
 ---
  - true
 ...
+lua box.cjson.encode{ box.socket.tcp_connect('invalid domain name') == nil, box.errno.strerror() }
+---
+ - [true,"Invalid argument"]
+...
 lua box.cjson.encode{ box.socket.tcp_connect('test:test@localhost:3303') == nil, box.errno.strerror() }
 ---
  - [true,"Invalid argument"]
diff --git a/test/box/bsdsocket.test b/test/box/bsdsocket.test
index 9e3c7454efdeaa88fc0f6d66fb13ecea1d7d616c..17a1c3729526fef712ac039251a1eb12b6245636 100644
--- a/test/box/bsdsocket.test
+++ b/test/box/bsdsocket.test
@@ -408,7 +408,7 @@ exec admin "lua s:close()"
 if os.path.exists(path):
     print 'unix socket was not removed: test failed'
 
-
+exec admin "lua box.cjson.encode{ box.socket.tcp_connect('invalid domain name') == nil, box.errno.strerror() }"
 exec admin "lua box.cjson.encode{ box.socket.tcp_connect('test:test@localhost:3303') == nil, box.errno.strerror() }"