[CONC-683] Closing a statement while another statement has a cursor opened causes erratic behaviour (random errors, hangs, crashes, etc) Created: 2024-01-16 Updated: 2024-01-16 |
|
| Status: | Open |
| Project: | MariaDB Connector/C |
| Component/s: | None |
| Affects Version/s: | 3.3.8 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Josep Yus | Assignee: | Georg Richter |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
| Description |
|
Closing a statement that has not started retrieval while there is a cursor opened in another statement causes the mariadb client to loose sync with the physical protocol state which in turn causes erratic behaviour in following interactions with the API: wrong return codes, crashes, hangs, etc Correct behaviour should be for "mysql_stmt_close" to close the current cursor (regardless of what statement opened it). Then attempts to fetch data from a cursor while there is none active (regardless of the statement used in the mysql_stmt_fetch call) should return an error saying there is no cursor opened. The interaction causing the issue to surface is: create stmt1 NOTE: The application I work on and where this causes wrong behaviour (crashes in my case) allows customers to choose how statements interact with connections. The customer can for instance use a connection per stmt or can decide to have concurrent statements using the same connection. This flexibility is in place since this application supports many other c connectors (oracle, postgres, etc) where retrieving data concurrently from different statements is supported by their respectives clients. In short, getting real useful errors indicating the interaction attempted is not supported by the underlying connector is ok but getting crashes or undeterministic behaviour is not. For your convenience I have attached a patch.diff (generated from "master") with test cases that reproduce this issue. The patch adds this test cases in the "ps_bugs" executable that comes as part of the mariadb c connector test suite. Also, I have done an initial investigation which shows that the culprit seems to be in line 379 (this is from "master" at the time of writing) in function mthd_stmt_flush_unbuffered() in file mariadb_stmt.c:
Please have a look. Thanks |
| Comments |
| Comment by Georg Richter [ 2024-01-16 ] |
|
Thanks for your bug report. I was able to reproduce this issue: The problem is that mysql_stmt_close(stmt2) doesn't return an error (commands out of sync). |
| Comment by Josep Yus [ 2024-01-16 ] |
|
Thanks for acknowledging this bug so quickly. If you come up with a quick patch let me know and I will be happy to test it before you push it. |