MySQL client error 2050 (CR_FETCH_CANCELED) means a row-fetch operation was aborted because mysql_stmt_close() was invoked before all rows were read.
MySQL Error 2050: CR_FETCH_CANCELED occurs when a client closes a prepared statement while rows are still being fetched, instantly canceling retrieval. Re-code your workflow to finish mysql_stmt_fetch() loops or buffer results before calling mysql_stmt_close() to fix the issue.
Row retrieval was canceled by mysql_stmt_close() call
Error 2050, condition name CR_FETCH_CANCELED, tells the MySQL client library that row retrieval stopped because mysql_stmt_close() was executed while a fetch loop was still active.
The error is raised on the client side, not the server, and is typical when using prepared statements through libmysql, MySQL C API, or language bindings such as PHP mysqli, Python mysql-connector, or Go database/sql.
The client library throws CR_FETCH_CANCELED when it detects that the statement handle was closed before all rows were consumed or buffered.
Premature closure interrupts the network protocol and leaves the server thinking the client has more rows to read.
Buffered mode hides the problem because rows are read eagerly, but unbuffered (streaming) mode exposes it. Long-running cursors, early returns, or exception paths often trigger the issue.
Always finish reading or storing every row returned by mysql_stmt_execute() before calling mysql_stmt_close().
Switch to buffered results when random access is needed or when the row count is modest.
Wrap fetch loops in try/finally blocks so the cleanup code only closes the statement after the loop completes. For language drivers, enable store_result() equivalents that fully download the result set first.
Applications that time-out long reports may kill the statement handle mid-stream.
Instead, cancel via KILL QUERY on the server and allow the client loop to exit gracefully.
Multithreaded programs sometimes share a statement handle; one thread closes it while another is fetching. Assign each thread its own connection or synchronize access to prevent conflicts.
Adopt buffered result mode for small to medium result sets.
When streaming large sets, ensure robust loop control that always drains or discards the remaining rows.
Instrument your code with connection/statement state logs. Monitoring libraries such as Galaxy’s query profiler can flag statements closed while busy, helping you catch the pattern early.
CR_SERVER_GONE_ERROR (2006) signals the opposite case where the server closed the connection. CR_COMMANDS_OUT_OF_SYNC (2014) appears when the client issues a new command before finishing the previous one.
Both can be mitigated with the same disciplined fetch-then-close workflow.
.
The error is tied to mysql_stmt_close(), which exists only in the prepared statement API. Non-prepared queries use different functions and error codes.
No server data is lost. The client simply stops reading rows, and the server frees the result set. The application, however, may miss unprocessed rows.
No. The error is client-side and unrelated to network timeouts. Focus on fetch and close ordering.
Galaxy’s SQL editor highlights unbuffered result usage and provides AI-generated linting tips that warn when a statement is closed inside an active fetch loop.