Random DB errors when using llng-fastcgi-server in foreground mode
Affected version
Version: 2.18.2
Platform: FastCGI server with the coudot/lemonldap-ng docker image
Summary
- I have customized the coudot/lemonldap-ng image to use CDBI with a mariadb server
- I encounter difficult to predict DB errors
- Errors can be easily triggered with high load and a disabled configuration cache
Logs
Some of the errors that pop up:
DBD::mysql::db selectrow_array failed: Unknown or undefined error code
...
DBD::mysql::db selectrow_arrayref failed: fetch() without execute()
Root cause
llng-fastcgi-server instanciates a handler during startup. This is needed to have shared status (apparently). But this action causes DBI to cache a connection to the database.
This connection cache is preserved after the process are forked by
- Plack startup (only when --foreground is not set)
- The FastCGI process manager (NPROC worker processes)
During the plack startup fork, the parent process exists, which runs DBI cleanup and closes the file descriptor, therefore invalidating the cache in other processes.
When --foreground is set, the file descriptor remains open and is reused until:
- That shared connection is closed by the SQL server
- One of the process terminates
Possible fixes
Either:
- Revert 019f1e75 and find another way to share the status server
- Find another way to have working docker logs without --foreground, and remove this option
- Fork llng-fastcgi-server one more time before handing control to Plack