Skip to content

Connection pool ignores SIGNALs after a successful query #639

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

Open
avoidwork opened this issue Nov 13, 2013 · 3 comments
Open

Connection pool ignores SIGNALs after a successful query #639

avoidwork opened this issue Nov 13, 2013 · 3 comments

Comments

@avoidwork
Copy link

Hi,

I noticed this today while a co-worker couldn't trigger an expected error case from our connection pool.

I use a UDF called "udf_uuidInternal()" to verify a record is valid, and it works fantastic in the DB, and from an sproc, but the dynamic SQL in place now returns the data for the last successful query even if a SIGNAL is sent saying the record is invalid.

If I start the API, and make a query with a known invalid UUID, I get the expected error and it's handled properly. If I then make a query with a valid UUID, I get the expected data. If I then re-use the first invalid UUID, get the data for the last successful query, without an error.

This is the UDF, it's pretty basic:

DROP FUNCTION IF EXISTS `udf_uuidInternal`;
delimiter ;;
CREATE FUNCTION `udf_uuidInternal`(xid char(40)) RETURNS bigint(20) unsigned
DETERMINISTIC
BEGIN
  DECLARE my_error CONDITION FOR SQLSTATE '45000';

  SELECT `uuid` FROM registry WHERE `guid` = xid INTO @result;

  IF @result IS NULL THEN
    SIGNAL my_error SET MESSAGE_TEXT = 'Record not found';
    SET @result = 'unknown';
  END IF;

  RETURN @result;
END
 ;;
delimiter ;
@avoidwork
Copy link
Author

I got the 'okay' for a $40+ bounty on this bad boy. Willing to discuss further if anyone can get this fixed before next weds.

@kai-koch
Copy link
Collaborator

Your function returns a string, if @result is null, but should return a BIGINT or null.
Also I am not sure about the scope of the @result variable, so try the follwing:

DROP FUNCTION IF EXISTS `udf_uuidInternal`;
delimiter ;;
CREATE FUNCTION `udf_uuidInternal`(xid char(40)) RETURNS bigint(20) unsigned
DETERMINISTIC
BEGIN
  DECLARE my_error CONDITION FOR SQLSTATE '45000';
  DECLARE result BIGINT UNSIGNED;

  SELECT `uuid` FROM registry WHERE `guid` = xid INTO result;

  IF result IS NULL THEN
    SIGNAL my_error SET MESSAGE_TEXT = 'Record not found';
  END IF;

  RETURN result;
END
 ;;
delimiter ;

@avoidwork
Copy link
Author

That's for logging purposes, and has no impact on the query because it doesn't run due to the SIGNAL from the UDF.

Sample usage:

SELECT * FROM users WHERE `id` = udf_internalUuid($uuid);

The driver bug shows itself by sending the rowpackets for the last query, because the 'invalid' ones never run.

dveeden pushed a commit to dveeden/mysql that referenced this issue Jan 31, 2023
Most forks won't be in goveralls and so this command in travis.yml was,
previously, failing and causing the build to fail.

Now, it doesn't!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants