spark
spark copied to clipboard
[BUG]: Semaphore Release Bug when an error occurs before GetConnection in JvmBridge
Describe the bug In JvmBridge, a semaphore is used to restrict the number of active sockets. The semaphore is waited for in GetConnection() and released in the finally block. Unfortunately there are calls before GetConnection() where the semaphore is acquired that are not guaranteed to always run successfully. In situations where there is an error before GetConnection(), the semaphore is never attempted to Wait() and the subsequent finally Release() yields an error that the semaphore count went over the max allowed.
Steps to repro (easy): The easiest way to make this happen is to add a throw new Exception("Test") block before the GetConnection() call.
Steps to reproduce the behavior (how I found it): I tried to make a dataFrame using the GenericRow[] and passed DateTime.Now as one of the objects. PayloadHelper.BuildPayload didn't like that and errored. This caused the semaphore counts to get out of whack.
Expected behavior Semaphores should always have perfect acquire/release guarantees.
I'll attempt a PR