Copilot commented on code in PR #44:
URL: 
https://github.com/apache/iotdb-client-csharp/pull/44#discussion_r2772376270


##########
src/Apache.IoTDB/ConcurrentClientQueue.cs:
##########
@@ -47,50 +48,51 @@ public void Return(Client client)
             Monitor.Exit(ClientQueue);
             Thread.Sleep(0);
         }

Review Comment:
   The Return method should wrap Monitor.Enter/Exit in a try-finally block for 
safety, similar to the Take method. If an exception occurs between 
Monitor.Enter and Monitor.Exit (e.g., at Monitor.PulseAll or 
ClientQueue.Enqueue), the lock would not be released, causing a deadlock. 
Consider refactoring to use try-finally protection.



##########
src/Apache.IoTDB/SessionPool.cs:
##########
@@ -1408,6 +1427,7 @@ public async Task<int> 
ExecuteNonQueryStatementAsync(string sql)
                     if (_database != previousDB)
                     {
                         // all client should switch to the same database
+                        var failedClients = new List<(long SessionId, 
Exception Error)>();
                         foreach (var c in _clients.ClientQueue)

Review Comment:
   The iteration over `_clients.ClientQueue` should use `.AsEnumerable()` for 
thread-safe enumeration, consistent with other usages in the codebase (see 
lines 383 and 407). Enumerating a ConcurrentQueue directly while other threads 
are enqueueing/dequeuing can lead to inconsistent snapshots or unexpected 
behavior. Change to `foreach (var c in _clients.ClientQueue.AsEnumerable())`.
   ```suggestion
                           foreach (var c in 
_clients.ClientQueue.AsEnumerable())
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to