Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLServerConnection infinite loop #2537

Open
haasc opened this issue Nov 12, 2024 · 1 comment
Open

SQLServerConnection infinite loop #2537

haasc opened this issue Nov 12, 2024 · 1 comment
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.

Comments

@haasc
Copy link

haasc commented Nov 12, 2024

Driver version

12.4.2

SQL Server version

Microsoft SQL Server 2022 (RTM-CU15-GDR) (KB5046059) - 16.0.4150.1 (X64) Sep 25 2024 17:34:41

Client Operating System

Ubuntu 20.04.06 LTS

JAVA/JVM version

java version "21.0.2" 2024-01-16 LTS

Table schema

Not needed

Problem description

We have a server that provides the client listeners for a. large number of messaging queue, which means it runs hundreds of threads draining 100+ queues. The thread uses the message to preform a series database inserts/updates.

The problem is that randomly, as the message processing completes so statements and connections are being closed/committed), a thread will get stuck in SQLServrConnection.endRquestInternal(), specifically on the loop in
sqlWarnings = originalSqlWarnings;
if (null != openStatements) {
while (!openStatements.isEmpty()) {
try (Statement st = openStatements.get(0)) {}
}
openStatements.clear();
}
Naively, shouldn't this loop not be an infinite loop, but have some form of timeout? Out of hundreds of threads running 24/7, its not unusual for us to lose 5-10 threads every couple of week to being stuck on this loop.

Expected behavior

The code should not get stuck in an infinite loop.

Actual behavior

The thread hangs in an infinite loop.

Error message/stack trace

A sample stack trace is below - note the cpu time.

"AccountListener-1" #305 [2606778] prio=5 os_prio=0 cpu=146605778.46ms elapsed=298559.22s tid=0x00007fdcb427d360 nid=2606778 runnable [0x0000
7fdc9dfdd000]
java.lang.Thread.State: RUNNABLE
at com.microsoft.sqlserver.jdbc.SQLServerConnection.endRequestInternal(SQLServerConnection.java:7367)
at com.microsoft.sqlserver.jdbc.SQLServerConnection43.endRequest(SQLServerConnection43.java:35)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$2.attemptNotifyEndRequest(C3P0PooledConnectionPool.java:182)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.markEndRequest(C3P0PooledConnectionPool.java:360)

Any other details that can be helpful

JDBC trace logs

@github-project-automation github-project-automation bot moved this to To be triaged in MSSQL JDBC Nov 12, 2024
@tkyc
Copy link
Contributor

tkyc commented Nov 12, 2024

Nvm, just realized. Reentrant locks are used. It's not deadlocking.

Could be looping infinitely because bIsClosed could be true. bIsClosed could have been set to true earlier somewhere. And so, when we call close() with the try-with-resources, the if-check on bIsClosed doesn't pass and closeInternal() can't removeOpenStatement(). So then we loop infinitely.

Thanks for the report. Will look into it.

@tkyc tkyc added the Bug A bug in the driver. A high priority item that one can expect to be addressed quickly. label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.
Projects
Status: Under Investigation
Development

No branches or pull requests

2 participants