Recently when attempting to upgrade php versions of the docker file that runs craft cms in a cloud run service, I started getting CloudSQL connection errors.
Example of logs.
2019-08-08T06:58:25.612096Z POST200 474 B 38 ms Chrome 75 /index.php?p=mangomin/actions/install/validate-db
2019-08-08T07:00:12.134410Z CloudSQL connection failed. Please see https://cloud.google.com/functions/docs/sql#troubleshooting for additional details: Post https://www.googleapis.com/sql/v1beta4/projects/c3gatsby-workflow-420fc457/instances/master-sql-f47f6b/createEphemeral?alt=json&prettyPrint=false: context deadline exceeded
2019-08-08T07:00:12.141939Z 169.254.8.129 - - [08/Aug/2019:07:00:02 +0000] "GET / HTTP/1.1" 503 52611 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"
2019-08-08T07:00:12.144019Z GET503 51.4 KB 10 s Chrome 75 /
2019-08-08T07:01:34.189448Z CloudSQL connection failed. Please see https://cloud.google.com/functions/docs/sql#troubleshooting for additional details: Post https://www.googleapis.com/sql/v1beta4/projects/c3gatsby-workflow-420fc457/instances/master-sql-f47f6b/createEphemeral?alt=json&prettyPrint=false: context deadline exceeded
2019-08-08T07:01:34.200976Z GET503 51.4 KB 10 s Chrome 75 /
This began happening this morning '8th August 2019'. Initially I thought it was just that the php version I upgraded too was not compatable with unix sockets or similar so I downgraded. That didn't work. So i continued to backtrack, to yesterdays revision (same env and docker sha) The issue persisted, I then backtracked to a stable docker release that I know is working on a sister cloud run service. No dice.
Put simply the only thing that I attempted to update is the docker file and how its built. (Trying to enable opcache which i found work work wonders locally for speeding up requests) Old
FROM php:7.1-apache
# Enable Reqrite and Headers for .htaccess
RUN a2enmod rewrite
RUN a2enmod headers
# Ensure UTF-8
RUN echo "AddDefaultCharset UTF-8" > /var/www/html/.htaccess
# Install linux dependencies
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
&& apt-get update --fix-missing \
&& apt-get install -y ssl-cert libmagickwand-dev libpq-dev zlib1g \
&& rm -rf /var/lib/apt/lists/*
# Install imagick
RUN pecl install imagick-3.4.3
# Install php extentions for docker
RUN docker-php-ext-enable imagick \
&& docker-php-ext-install pdo pdo_mysql zip
# Enable SSL apache2
RUN a2ensite default-ssl \
&& a2enmod ssl
# Replace the default served file to /web
RUN sed -i 's%/var/www/html%/var/www/html/web%g' /etc/apache2/sites-enabled/*.conf
# Use the PORT environment variable in Apache configuration files.
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-enabled/000-default.conf /etc/apache2/ports.conf
# Replace with production mode
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
# Up the upload file size limit, memory limit and max-execution time
RUN sed -i "s/max_input_time = 30/max_input_time = 120/g" "$PHP_INI_DIR/php.ini"
RUN sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 5M/g" "$PHP_INI_DIR/php.ini"
RUN sed -i "s/max_execution_time = 30/max_execution_time = 120/g" "$PHP_INI_DIR/php.ini"
RUN sed -i "s/memory_limit = 128M/memory_limit = 256M/g" "$PHP_INI_DIR/php.ini"
New
FROM php:7.3-apache-stretch
# Enable Reqrite and Headers for .htaccess
RUN a2enmod rewrite
RUN a2enmod headers
# Ensure UTF-8
RUN echo "AddDefaultCharset UTF-8" > /var/www/html/.htaccess
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS"
# Install linux dependencies
RUN apt-get update --fix-missing \
&& apt-get install -y libfreetype6-dev libjpeg62-turbo-dev \
libpng-dev libbz2-dev \
libssl-dev autoconf \
ca-certificates curl g++ libicu-dev mysql-client \
ssl-cert libmagickwand-dev libpq-dev zlib1g libzip-dev \
&& rm -rf /var/lib/apt/lists/*
# Install imagick
RUN pecl install imagick-3.4.3
# Install php extentions for docker
RUN docker-php-ext-enable imagick
RUN docker-php-ext-install bcmath bz2 exif \
gd gettext mbstring opcache
RUN docker-php-ext-install shmop sockets sysvmsg sysvsem sysvshm \
zip iconv pdo_mysql intl
# Enable SSL apache2
RUN a2ensite default-ssl \
&& a2enmod ssl
COPY php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
PHP_OPCACHE_MAX_ACCELERATED_FILES="10000" \
PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10"
# Replace the default served file to /web
RUN sed -i 's%/var/www/html%/var/www/html/web%g' /etc/apache2/sites-enabled/*.conf
# Use the PORT environment variable in Apache configuration files.
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-enabled/000-default.conf /etc/apache2/ports.conf
# Replace with production mode
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
# Up the upload file size limit, memory limit and max-execution time
RUN sed -i "s/max_input_time = 30/max_input_time = 120/g" "$PHP_INI_DIR/php.ini" && \
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 10M/g" "$PHP_INI_DIR/php.ini" && \
sed -i "s/max_execution_time = 30/max_execution_time = 120/g" "$PHP_INI_DIR/php.ini" && \
sed -i "s/memory_limit = 128M/memory_limit = 512M/g" "$PHP_INI_DIR/php.ini"
I apologize for posting whole files.
Expected and actual results have already been explained.
Some observations that i have found is that the time outs are exactly 10 seconds, If this has anything to do with something.
Any help will be appreciated.
Thank you in advance.