THRIFT-3012 Timing problems in NamedPipe implementation due to unnecessary open/close
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Transport.Pipes.pas b/lib/delphi/src/Thrift.Transport.Pipes.pas
index 48eb5e2..593bb3a 100644
--- a/lib/delphi/src/Thrift.Transport.Pipes.pas
+++ b/lib/delphi/src/Thrift.Transport.Pipes.pas
@@ -227,7 +227,7 @@
   public
     constructor Create( aPipename : string; aBufsize : Cardinal = 4096;
                         aMaxConns : Cardinal = PIPE_UNLIMITED_INSTANCES;
-                        aTimeOut : Cardinal = 0);
+                        aTimeOut : Cardinal = INFINITE);
   end;
 
 
@@ -816,10 +816,11 @@
   overlapped := TOverlappedHelperImpl.Create;
 
   ASSERT( not FConnected);
+  CreateNamedPipe;
   while not FConnected do begin
-    InternalClose;
-    if QueryStopServer then Abort;
-    CreateNamedPipe;
+
+    if QueryStopServer
+    then Abort;
 
     if Assigned(fnAccepting)
     then fnAccepting();
diff --git a/lib/delphi/test/TestClient.pas b/lib/delphi/test/TestClient.pas
index 6f155a2..ec30109 100644
--- a/lib/delphi/test/TestClient.pas
+++ b/lib/delphi/test/TestClient.pas
@@ -481,18 +481,19 @@
   except
     on e:TTransportException do begin
       Console.WriteLine( e.ClassName+' = '+e.Message); // this is what we get
-      if FTransport.IsOpen then FTransport.Close;
-      FTransport.Open;   // re-open connection, server has already closed
     end;
     on e:TApplicationException do begin
       Console.WriteLine( e.ClassName+' = '+e.Message); // this is what we get
-      if FTransport.IsOpen then FTransport.Close;
-      FTransport.Open;   // re-open connection, server has already closed
     end;
     on e:TException do Expect( FALSE, 'Unexpected exception type "'+e.ClassName+'"');
     on e:Exception do Expect( FALSE, 'Unexpected exception type "'+e.ClassName+'"');
   end;
 
+  {
+  if FTransport.IsOpen then FTransport.Close;
+  FTransport.Open;   // re-open connection, server has already closed
+  }
+
   // case 3: no exception
   try
     client.testException('something');
diff --git a/lib/delphi/test/TestServer.pas b/lib/delphi/test/TestServer.pas
index ad4823f..55384ed 100644
--- a/lib/delphi/test/TestServer.pas
+++ b/lib/delphi/test/TestServer.pas
@@ -536,11 +536,6 @@
   endpoint : TEndpointTransport;
   layered : TLayeredTransports;
   UseSSL : Boolean; // include where appropriate (TLayeredTransport?)
-const
-  // pipe timeouts to be used
-  DEBUG_TIMEOUT   = 30 * 1000;
-  RELEASE_TIMEOUT = DEFAULT_THRIFT_TIMEOUT;  // server-side default
-  TIMEOUT         = RELEASE_TIMEOUT;
 begin
   try
     ServerEvents := FALSE;
@@ -663,7 +658,7 @@
 
       trns_NamedPipes : begin
         Console.WriteLine('- named pipe ('+sPipeName+')');
-        namedpipe   := TNamedPipeServerTransportImpl.Create( sPipeName, 4096, PIPE_UNLIMITED_INSTANCES, TIMEOUT);
+        namedpipe   := TNamedPipeServerTransportImpl.Create( sPipeName, 4096, PIPE_UNLIMITED_INSTANCES);
         servertrans := namedpipe;
       end;