From d6cd60bd44c5215be54b40820e6d6f69c3e6c67d Mon Sep 17 00:00:00 2001
From: "Dmitry E. Oboukhov" <unera@debian.org>
Date: Sun, 2 Jun 2013 12:18:19 +0400
Subject: [PATCH] Fix possible race condition between read/write fibers.

---
 src/box/lua/box_net.lua | 9 ++++++---
 test/box/net.box.result | 4 ++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/box/lua/box_net.lua b/src/box/lua/box_net.lua
index f7624b182b..d84b130e7e 100644
--- a/src/box/lua/box_net.lua
+++ b/src/box/lua/box_net.lua
@@ -284,19 +284,22 @@ box.net.box.new = function(host, port, reconnect_timeout)
             if self.s ~= nil then
                 return true
             end
-            self.s = box.socket.tcp()
-            if self.s == nil then
+
+            local sc = box.socket.tcp()
+            if sc == nil then
                 self:fatal("Can't create socket")
                 return false
             end
 
-            local s = { self.s:connect( self.host, self.port ) }
+            local s = { sc:connect( self.host, self.port ) }
             if s[1] == nil then
                 self:fatal("Can't connect to %s:%s: %s",
                     self.host, self.port, s[4])
                 return false
             end
 
+            self.s = sc
+
             return true
         end,
 
diff --git a/test/box/net.box.result b/test/box/net.box.result
index ad130a494b..89b69c3cfd 100644
--- a/test/box/net.box.result
+++ b/test/box/net.box.result
@@ -173,9 +173,9 @@ lua remote:close()
 ...
 lua remote:close()
 ---
-error: '[string "box.net = {..."]:399: box.net.box: already closed'
+error: '[string "box.net = {..."]:402: box.net.box: already closed'
 ...
 lua remote:ping()
 ---
-error: '[string "box.net = {..."]:404: box.net.box: connection was closed'
+error: '[string "box.net = {..."]:407: box.net.box: connection was closed'
 ...
-- 
GitLab