shlinkio / shlink

The definitive self-hosted URL shortener
https://shlink.io
MIT License
3.28k stars 261 forks source link

PDOException - Queries not buffered by default #750

Closed jmadureira closed 4 years ago

jmadureira commented 4 years ago

How Shlink is set-up

Summary

Got the following error white trying to create short URLs concurrently:

PDOException: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in /etc/shlink/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:121

I noticed that query buffering has been added to shlink on v2.2.0-alpha.1 at /docker/config/shlink_in_docker.local.php which ought to fix this issue. Is it possible to include this change on the 1.21 banch as well?

Expected behavior

No errors should the logged

How to reproduce

Configure webhooks to receive notifications every time a link is clicked.

Make concurrent requests to both create short urls and visit links.

acelaya commented 4 years ago

Hey @jmadureira

Yes, that's a weird bug that has been recently fixed. Actually it's not really part of v2.2.0-alpha.1, as I thought I had it fixed just to later find out the issue was still there and the fix was different.

The fix is actually this: https://github.com/shlinkio/shlink/commit/56932e4ea6904c5acfe3f77387ddef97e181ba6a

I also cannot backport it, as v1.x is no longer maintained. I might consider providing fixes for high-severity security issues, but that's all.

However, there's an easy way for you to workaround this issue.

The docker image allows you to pass a configuration file that gets merged with the app config: https://shlink.io/documentation/install-docker-image/#provide-config-via-volumes

Some common configuration is documented there, but you can virtually overwrite any configuration value using this approach.

If you provide a config file with this content, you will be overwriting the malfunctioning config param:

{
  "zend-expressive-swoole": {
    "enable_coroutine": false
  }
}

Let me know if that helped.

acelaya commented 4 years ago

Sorry, my bad. I have just realized v1.X was still using the old Zend components, so the main key would not be mezzio-swoole but zend-expressive-swoole instead.

I have edited the comment.

jmadureira commented 4 years ago

Hello @acelaya

Thanks for the reply.

I'll have some work to do then. I'll be closing this issue since the target version is no longer maintained.