Grasshopper gives internal server error if requests back to back

Hi ,

I have made one custom endpoint which calls the grasshopper definition and provides it a json input. I have hosted it on ec2 instance. when the first 2 or 3 requests come it works correctly and gives the results. when more requests come it starts to give internal server error 500.

To be more precise there is no parallel request processing is going on. all the requests stays in queue and they get process sequentially. I am attaching the below code that I have implemented for the custom endpoint. Initially I thought may cache issue is there due to which it starts breaking after certain requests hence I clear it with gH_ComponentServer.Clear(); but it does not work

   private string ExecuteDefinitionSingleParameter(string definitionPath)
   {
       List<GrasshopperDataTree> inputParams = null;
       List<GrasshopperDataTree> results = null;
       GH_ComponentServer gH_ComponentServer = new GH_ComponentServer();

       try
       {

           if (string.IsNullOrWhiteSpace(definitionPath))
               throw new ArgumentNullException(nameof(definitionPath),
                   "Grasshopper definition path is missing or invalid.");

           inputParams = BuildInputParamsSingleParameter();
           results = GrasshopperCompute.EvaluateDefinition(definitionPath, inputParams).ToList();

           if (results == null || results.Count == 0)
               throw new InvalidOperationException("No results returned from Grasshopper definition.");

           Log($"Definition executed successfully: {definitionPath}");

           return "Definition executed successfully";
       }
       catch (Exception ex)
       {
           Log($"Error in ExecuteDefinition: {ex}");
           return $"Error running analyzer: {ex.Message}";
       }
       finally
       {
           // CRITICAL: break references
           results = null;
           inputParams = null;
           gH_ComponentServer.Clear();
           Rhino.RhinoDoc.ActiveDoc?.Objects.Clear();
           GC.Collect();
           GC.WaitForPendingFinalizers();
           GC.Collect();
       }

in some logs I find this
CG [13:48:46 WRN] As of “01/10/2026 08:18:45 +00:00”, the heartbeat has been running for “00:02:47.5370368” which is longer than “00:00:01”. This could be caused by thread pool starvation.
RC [13:49:39 INF] Max concurrent requests = 2
CG [13:49:41 WRN] As of “01/10/2026 08:19:41 +00:00”, the heartbeat has been running for “00:00:53.0065572” which is longer than “00:00:01”. This could be caused by thread pool starvation.

Hi @Shivam_Mahajan ,

GHCompute.EvluateDefinition is blocking threads for too long and the thread pool can’t keep up. After 2-3 requests there are no available threads left to handle new requests and you get 500 error.
Hope this helps,
Farouk

@farouk.serragedine my understanding was once the request is processed that threads get back into pool because at the end of the request it returns “Definition executed successfully”. Is this understanding not right ? or GrasshopperCompute is static and it remains in memory as long as compute is running ?