Skip to content

Conversation

@toddmeng-db
Copy link
Contributor

@toddmeng-db toddmeng-db commented May 22, 2025

DatabricksOperationStatusPoller was interleaving calls with CloudFetchResultFetcher. Since they both share the underlying transport and protocol to perform this operation (and TTransport is not thread-safe), it resulted in race conditions between status polling and result fetching.

This PR fixes this by adding a ThreadSafeClient to classes sharing a connection/protocol/transport. This PR should not affect Impala's client

Testing

Ran CloudFetchE2Etests, passes on this branch (fails on main)

@toddmeng-db toddmeng-db force-pushed the toddmeng-db/polling-thread-safety branch 2 times, most recently from fe1fb11 to f1dcafb Compare May 23, 2025 00:08
@toddmeng-db toddmeng-db changed the title Client lock to prevent fetch result and polling race feat(csharp/src/Drivers/Databricks): Client lock to prevent fetch result and polling race May 23, 2025
@toddmeng-db toddmeng-db changed the title feat(csharp/src/Drivers/Databricks): Client lock to prevent fetch result and polling race feat(csharp/src/Drivers/Databricks): Fixes to heartbeat polling May 23, 2025
@toddmeng-db toddmeng-db force-pushed the toddmeng-db/polling-thread-safety branch 2 times, most recently from 80b7725 to a54830b Compare May 23, 2025 00:47
@toddmeng-db toddmeng-db force-pushed the toddmeng-db/polling-thread-safety branch from a54830b to 0d468e6 Compare May 23, 2025 01:57
@toddmeng-db toddmeng-db force-pushed the toddmeng-db/polling-thread-safety branch 8 times, most recently from ca59bd0 to 446e97a Compare May 23, 2025 19:14
/// This is used to maintain the command results and session when reading results takes a long time.
/// </summary>
internal class DatabricksOperationStatusPoller : IDisposable
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the client doesn't finish reading results, but does not call statement.Dispose() explicitly, this will keep polling continuously.

One (slight hacky solution) could be to use a WeakReference to the DatabricksStatement or BaseDatabricksReader to end polling after Garbage disposal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding this as a kind of "Known Issues" in the readme.md.

@toddmeng-db toddmeng-db force-pushed the toddmeng-db/polling-thread-safety branch from 446e97a to 8ada32f Compare May 23, 2025 19:27
DatabricksStatement thread-safe ownership

fix unit tests
@toddmeng-db toddmeng-db force-pushed the toddmeng-db/polling-thread-safety branch from d856e9c to 3c7bb78 Compare May 23, 2025 22:37
@toddmeng-db toddmeng-db force-pushed the toddmeng-db/polling-thread-safety branch from 3c7bb78 to ca395a8 Compare May 23, 2025 22:38
@toddmeng-db toddmeng-db marked this pull request as ready for review May 26, 2025 07:46
@github-actions github-actions bot added this to the ADBC Libraries 19 milestone May 26, 2025
Copy link
Contributor

@CurtHagenlocher CurtHagenlocher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; looks good!

@CurtHagenlocher CurtHagenlocher merged commit 00721ca into apache:main May 27, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants