@@ -37,6 +37,7 @@ namespace OpenQA.Selenium
3737    public  abstract  class  DriverService  :  ICommandServer 
3838    { 
3939        private  bool  isDisposed ; 
40+         private  readonly  object  driverServiceProcessLock  =  new  object ( ) ; 
4041        private  Process ?  driverServiceProcess ; 
4142
4243        /// <summary> 
@@ -242,40 +243,47 @@ public async Task StartAsync()
242243                return ; 
243244            } 
244245
245-             var  driverServiceProcess  =  new  Process ( ) ; 
246- 
247-             try 
246+             lock  ( this . driverServiceProcessLock ) 
248247            { 
249-                 if  ( this . DriverServicePath  !=  null ) 
248+ 
249+                 if  ( this . driverServiceProcess  ==  null ) 
250250                { 
251-                     if  ( this . DriverServiceExecutableName  is  null ) 
251+                     var  driverServiceProcess  =  new  Process ( ) ; 
252+ 
253+                     try 
252254                    { 
253-                         throw  new  InvalidOperationException ( "If the driver service path is specified, the driver service executable name must be as well" ) ; 
254-                     } 
255+                         if  ( this . DriverServicePath  !=  null ) 
256+                         { 
257+                             if  ( this . DriverServiceExecutableName  is  null ) 
258+                             { 
259+                                 throw  new  InvalidOperationException ( "If the driver service path is specified, the driver service executable name must be as well" ) ; 
260+                             } 
255261
256-                     driverServiceProcess . StartInfo . FileName  =  Path . Combine ( this . DriverServicePath ,  this . DriverServiceExecutableName ) ; 
257-                 } 
258-                 else 
259-                 { 
260-                     driverServiceProcess . StartInfo . FileName  =  new  DriverFinder ( this . GetDefaultDriverOptions ( ) ) . GetDriverPath ( ) ; 
261-                 } 
262+                              driverServiceProcess . StartInfo . FileName  =  Path . Combine ( this . DriverServicePath ,  this . DriverServiceExecutableName ) ; 
263+                          } 
264+                          else 
265+                          { 
266+                              driverServiceProcess . StartInfo . FileName  =  new  DriverFinder ( this . GetDefaultDriverOptions ( ) ) . GetDriverPath ( ) ; 
267+                          } 
262268
263-                 driverServiceProcess . StartInfo . Arguments  =  this . CommandLineArguments ; 
264-                 driverServiceProcess . StartInfo . UseShellExecute  =  false ; 
265-                 driverServiceProcess . StartInfo . CreateNoWindow  =  this . HideCommandPromptWindow ; 
269+                          driverServiceProcess . StartInfo . Arguments  =  this . CommandLineArguments ; 
270+                          driverServiceProcess . StartInfo . UseShellExecute  =  false ; 
271+                          driverServiceProcess . StartInfo . CreateNoWindow  =  this . HideCommandPromptWindow ; 
266272
267-                 DriverProcessStartingEventArgs  eventArgs  =  new  DriverProcessStartingEventArgs ( driverServiceProcess . StartInfo ) ; 
268-                 this . OnDriverProcessStarting ( eventArgs ) ; 
273+                          DriverProcessStartingEventArgs  eventArgs  =  new  DriverProcessStartingEventArgs ( driverServiceProcess . StartInfo ) ; 
274+                          this . OnDriverProcessStarting ( eventArgs ) ; 
269275
270-                 driverServiceProcess . Start ( ) ; 
271-             } 
272-             catch 
273-             { 
274-                 driverServiceProcess . Dispose ( ) ; 
275-                 throw ; 
276-             } 
276+                          driverServiceProcess . Start ( ) ; 
277+                      } 
278+                      catch 
279+                      { 
280+                          driverServiceProcess . Dispose ( ) ; 
281+                          throw ; 
282+                      } 
277283
278-             this . driverServiceProcess  =  driverServiceProcess ; 
284+                     this . driverServiceProcess  =  driverServiceProcess ; 
285+                 } 
286+             } 
279287
280288            bool  serviceAvailable  =  await  this . WaitForServiceInitializationAsync ( ) . ConfigureAwait ( false ) ; 
281289            DriverProcessStartedEventArgs  processStartedEventArgs  =  new  DriverProcessStartedEventArgs ( driverServiceProcess ) ; 
0 commit comments