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

Racing condition results in error message as response but still http 200 #2538

larsschaps opened this issue Jul 30, 2019 · 3 comments


Copy link

commented Jul 30, 2019

Describe the bug
When putting load on yourls, it can happen that it tries to insert the same key again. This results in a db error, which message is send as respone with http 200.

To Reproduce

Put load on service with parallel curl commands;

for i in {1..5}; do curl -w'\n' -sSiv --raw "https://<host>/yourls-api.php?action=shorturl&format=simple&signature=<sig>&url=http%3A%2F%2F<url>" & done

You might want to increase the counter and/or try it several times.

Expected behavior

Catch the db exception, because it could be handled, either

  • retry or
  • respond with http status 500 (Internal server error) or maybe 503 (service unavailable)

Catch all unkown exceptions and respond with 500, log error.

Actual behavior

Response is the db error message with HTTP/1.1 200 OK


HTTP/1.1 200 OK

 <br />
<b>Fatal error</b>:  Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1hwza' for key 'PRIMARY' in 
Stack trace:
#0 /var/www/html/includes/vendor/aura/sql/src/ExtendedPdo.php(748): PDOStatement-&gt;execute()
#1 /var/www/html/includes/vendor/aura/sql/src/ExtendedPdo.php(306): Aura\Sql\ExtendedPdo-&gt;perform('INSERT INTO `yo...', Array)
#2 /var/www/html/includes/functions.php(161): Aura\Sql\ExtendedPdo-&gt;fetchAffected('INSERT INTO `yo...', Array)
#3 /var/www/html/includes/functions.php(278): yourls_insert_link_in_db('http://www.XXXX...', '1hwza', 'http://www.qweq...')
#4 /var/www/html/includes/functions-api.php(21): yourls_add_new_link('http://www.XXXX...', '1hwza', 'http://www.XXXX...')
#5 /var/www/html/includes/functions-plugins.php(150): yourls_api_action_shorturl(false)
#6 /var/www/html/yourls-api.php(35): yourls_apply_filter('api_action_shor...', false)
#7 {main}
  thrown in <b>/var/www/html/includes/vendor/aura/sql/src/ExtendedPdo.php</b> on line <b>748</b><br />

1.7.2 on Google Cloud Kubernetes

@larsschaps larsschaps added the bug label Jul 30, 2019


This comment has been minimized.

Copy link

commented Jul 30, 2019

Yeah, more or less know problem. Might want to check API Concurrency Plugin. Very open to tested patch improving things.

@ozh ozh closed this Jul 30, 2019


This comment has been minimized.

Copy link

commented Jul 31, 2019

This issue seems to pop up with v1.7.3 only. All versions before v1.7.3 don't have this issue. In my point of view definitely a bug.


This comment has been minimized.

Copy link

commented Jul 31, 2019

@ozh btw why did you close the issue when this bug is known and still open?

@ozh ozh reopened this Aug 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.