Limiting Surrogate Processes for Query Execution
I am using LINQPad for diagnostic purposes by referencing the assemblies and functionality used by our service hosts. It will ultimately open up ports for taking requests as well as connecting to our database. The reason for doing this is so I can have access to data such as preferences, permissions, etc. that are serialized in an encoded binary format in our database. It works well at replacing our testing console host, and I can prototype new code there as well.
The problem I am running into is that my LINQPad scripts initialize our system (connecting to the DB, opening up ports for listening, etc.) working fine the first time, but when running a second time, complains about something already listening on the same port. I then run the script a third time and it works correctly. It exhibits this same pattern consistently... every odd number try works, every even number try fails.
One thing I noticed when attaching the debugger, is that it seems there are potentially two surrogate processes that are hosting the query (LINQPad.UserrQuery.exe) and both of them are children of the main LINQPad.exe executable. In order for my hosted application to run correctly, I've had to make sure that the Execution properties of the query are set as follows:
I tend to suspect that LINQPad is probably alternating each of my runs between the two different surrogate processes which is why one works each time and still keeps the port open, while the other one ends up with the error because the other is listening on the ports. While I will probably modify my test harness to completely shut down the engine each time, I am wondering if there is any type of configuration setting which controls the number of child surrogate processes LINQPad creates for executing queries. I feel if I cut this down to one instead of two, I could at least avoid the alternating run problem.