question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error 500 after period of inactivity

See original GitHub issue

Issue Summary

After a period of inactivity (in my case about a day or so) the database connection seems to be closed. When I visit the frontpage I get presented with an error 500 (see screenshot). I am using a docker deployment with mysql as the database technology.

To Reproduce

  1. Deploy the stackfile: docker stack deploy report --compose-file ./stack.yml
  2. Wait for a day (don’t visit the site)
  3. Visit the site and see the error 500

image My stack file:

version: '3.6'

services:
  ghost:
    image: ghost
    ports:
      - 80:2368
    environment:
      url: https://my.url
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: randomly_generated
      database__connection__database: ghost
    volumes:
      - ghost:/var/lib/ghost/content

  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: randomly_generated
    volumes:
      - mysql:/var/lib/mysql

volumes:
  ghost:
  mysql:

Logs:

2018-06-19T07:54:31.620481474Z [2018-06-19 07:54:31] ERROR
2018-06-19T07:54:31.620518661Z 
2018-06-19T07:54:31.620526193Z CODE: ECONNRESET
2018-06-19T07:54:31.620532453Z MESSAGE: select `clients`.* from `clients` where `clients`.`slug` = 'ghost-frontend' and `clients`.`type` = 'ua' limit 1 - read ECONNRESET
2018-06-19T07:54:31.620538871Z 
2018-06-19T07:54:31.620544563Z Error: read ECONNRESET
2018-06-19T07:54:31.620550436Z     at exports._errnoException (util.js:1020:11)
2018-06-19T07:54:31.620556321Z     at TCP.onread (net.js:580:26)
2018-06-19T07:54:31.620562180Z     --------------------
2018-06-19T07:54:31.620567996Z     at Protocol._enqueue (/var/lib/ghost/versions/1.24.2/node_modules/mysql/lib/protocol/Protocol.js:145:48)
2018-06-19T07:54:31.620574107Z     at Connection.query (/var/lib/ghost/versions/1.24.2/node_modules/mysql/lib/Connection.js:208:25)
2018-06-19T07:54:31.620580107Z     at /var/lib/ghost/versions/1.24.2/node_modules/knex/lib/dialects/mysql/index.js:161:18
2018-06-19T07:54:31.620586080Z     at Promise._execute (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/debuggability.js:303:9)
2018-06-19T07:54:31.620592130Z     at Promise._resolveFromExecutor (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/promise.js:483:18)
2018-06-19T07:54:31.620598328Z     at new Promise (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/promise.js:79:10)
2018-06-19T07:54:31.620604372Z     at Client_MySQL._query (/var/lib/ghost/versions/1.24.2/node_modules/knex/lib/dialects/mysql/index.js:155:12)
2018-06-19T07:54:31.620610420Z     at Client_MySQL.query (/var/lib/ghost/versions/1.24.2/node_modules/knex/lib/client.js:206:17)
2018-06-19T07:54:31.620616377Z     at Runner.<anonymous> (/var/lib/ghost/versions/1.24.2/node_modules/knex/lib/runner.js:155:36)
2018-06-19T07:54:31.620622505Z     at Runner.tryCatcher (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/util.js:16:23)
2018-06-19T07:54:31.620637647Z     at Runner.query (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/method.js:15:34)
2018-06-19T07:54:31.620644199Z     at /var/lib/ghost/versions/1.24.2/node_modules/knex/lib/runner.js:61:21
2018-06-19T07:54:31.620650077Z     at tryCatcher (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/util.js:16:23)
2018-06-19T07:54:31.620655962Z     at /var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/using.js:185:26
2018-06-19T07:54:31.620661835Z     at tryCatcher (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/util.js:16:23)
2018-06-19T07:54:31.620667734Z     at Promise._settlePromiseFromHandler (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/promise.js:512:31)
2018-06-19T07:54:31.620673672Z 
2018-06-19T07:54:31.628986660Z ERROR [2018-06-19 07:54:31] "GET /" 500 13ms
2018-06-19T07:54:31.629074994Z 
2018-06-19T07:54:31.629083165Z NAME: InternalServerError
2018-06-19T07:54:31.629089226Z CODE: ECONNRESET
2018-06-19T07:54:31.629095005Z MESSAGE: select count(distinct posts.id) as aggregate from `posts` where (`posts`.`status` = 'published') and (`posts`.`page` = false) - read ECONNRESET
2018-06-19T07:54:31.629101133Z 
2018-06-19T07:54:31.629106596Z level:normal
2018-06-19T07:54:31.629112373Z 
2018-06-19T07:54:31.629117931Z InternalServerError: select count(distinct posts.id) as aggregate from `posts` where (`posts`.`status` = 'published') and (`posts`.`page` = false) - read ECONNRESET
2018-06-19T07:54:31.629124042Z     at new GhostError (/var/lib/ghost/versions/1.24.2/core/server/lib/common/errors.js:9:26)
2018-06-19T07:54:31.629129843Z     at prepareError (/var/lib/ghost/versions/1.24.2/core/server/web/middleware/error-handler.js:39:19)
2018-06-19T07:54:31.629145234Z     at Layer.handle_error (/var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/layer.js:71:5)
2018-06-19T07:54:31.629152560Z     at trim_prefix (/var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/index.js:315:13)
2018-06-19T07:54:31.629158445Z     at /var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/index.js:284:7
2018-06-19T07:54:31.629164140Z     at Function.process_params (/var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/index.js:335:12)
2018-06-19T07:54:31.629169923Z     at next (/var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/index.js:275:10)
2018-06-19T07:54:31.629175671Z     at Layer.handle_error (/var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/layer.js:67:12)
2018-06-19T07:54:31.629214708Z     at trim_prefix (/var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/index.js:315:13)
2018-06-19T07:54:31.629223386Z     at /var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/index.js:284:7
2018-06-19T07:54:31.629229400Z     at Function.process_params (/var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/index.js:335:12)
2018-06-19T07:54:31.629240146Z     at Immediate.next (/var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/index.js:275:10)
2018-06-19T07:54:31.629246653Z     at Immediate.<anonymous> (/var/lib/ghost/versions/1.24.2/node_modules/express/lib/router/index.js:635:15)
2018-06-19T07:54:31.629252729Z     at runCallback (timers.js:674:20)
2018-06-19T07:54:31.629258373Z     at tryOnImmediate (timers.js:645:5)
2018-06-19T07:54:31.629263989Z     at processImmediate [as _immediateCallback] (timers.js:617:5)
2018-06-19T07:54:31.629269658Z 
2018-06-19T07:54:31.629275063Z Error: read ECONNRESET
2018-06-19T07:54:31.629289926Z     at exports._errnoException (util.js:1020:11)
2018-06-19T07:54:31.629297816Z     at TCP.onread (net.js:580:26)
2018-06-19T07:54:31.629303669Z     --------------------
2018-06-19T07:54:31.629309329Z     at Protocol._enqueue (/var/lib/ghost/versions/1.24.2/node_modules/mysql/lib/protocol/Protocol.js:145:48)
2018-06-19T07:54:31.629315290Z     at Connection.query (/var/lib/ghost/versions/1.24.2/node_modules/mysql/lib/Connection.js:208:25)
2018-06-19T07:54:31.629321062Z     at /var/lib/ghost/versions/1.24.2/node_modules/knex/lib/dialects/mysql/index.js:161:18
2018-06-19T07:54:31.629326828Z     at Promise._execute (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/debuggability.js:303:9)
2018-06-19T07:54:31.629332879Z     at Promise._resolveFromExecutor (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/promise.js:483:18)
2018-06-19T07:54:31.629338756Z     at new Promise (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/promise.js:79:10)
2018-06-19T07:54:31.629344616Z     at Client_MySQL._query (/var/lib/ghost/versions/1.24.2/node_modules/knex/lib/dialects/mysql/index.js:155:12)
2018-06-19T07:54:31.629350571Z     at Client_MySQL.query (/var/lib/ghost/versions/1.24.2/node_modules/knex/lib/client.js:206:17)
2018-06-19T07:54:31.629356402Z     at Runner.<anonymous> (/var/lib/ghost/versions/1.24.2/node_modules/knex/lib/runner.js:155:36)
2018-06-19T07:54:31.629362380Z     at Runner.tryCatcher (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/util.js:16:23)
2018-06-19T07:54:31.629368185Z     at Runner.query (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/method.js:15:34)
2018-06-19T07:54:31.629374020Z     at /var/lib/ghost/versions/1.24.2/node_modules/knex/lib/runner.js:61:21
2018-06-19T07:54:31.629379660Z     at tryCatcher (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/util.js:16:23)
2018-06-19T07:54:31.629385388Z     at /var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/using.js:185:26
2018-06-19T07:54:31.629391175Z     at tryCatcher (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/util.js:16:23)
2018-06-19T07:54:31.629397077Z     at Promise._settlePromiseFromHandler (/var/lib/ghost/versions/1.24.2/node_modules/bluebird/js/release/promise.js:512:31)
2018-06-19T07:54:31.629403105Z 
2018-06-19T07:54:31.753664948Z INFO [2018-06-19 07:54:31] "GET /assets/built/screen.css?v=eee8f52bf2" 200 1ms
2018-06-19T07:54:31.903233465Z INFO [2018-06-19 07:54:31] "GET /favicon.ico" 302 6ms
2018-06-19T07:54:31.929420024Z INFO [2018-06-19 07:54:31] "GET /favicon.ico" 302 2ms
2018-06-19T07:54:55.043872223Z INFO [2018-06-19 07:54:55] "GET /" 200 36ms
2018-06-19T07:54:55.157143346Z INFO [2018-06-19 07:54:55] "GET /assets/built/screen.css?v=eee8f52bf2" 304 2ms
2018-06-19T07:54:55.169146742Z INFO [2018-06-19 07:54:55] "GET /public/ghost-sdk.min.js?v=eee8f52bf2" 200 0ms
2018-06-19T07:54:55.180905659Z INFO [2018-06-19 07:54:55] "GET /assets/js/jquery.fitvids.js?v=eee8f52bf2" 304 2ms
2018-06-19T07:54:55.182154748Z INFO [2018-06-19 07:54:55] "GET /assets/js/infinitescroll.js?v=eee8f52bf2" 304 3ms
2018-06-19T07:54:55.206722352Z INFO [2018-06-19 07:54:55] "GET /content/images/2018/06/graphic_400px.png" 200 3ms
2018-06-19T07:54:55.237869105Z INFO [2018-06-19 07:54:55] "GET /content/images/2018/06/zany-jadraque-571205-unsplash.jpg" 304 1ms
2018-06-19T07:58:25.211952872Z INFO [2018-06-19 07:58:25] "GET /content/images/2018/06/zany-jadraque-571205-unsplash.jpg" 200 18ms

Technical details:

  • Ghost Version: 1.24.2 docker ghost:latest (tag: sha256:75330bf68e42823a8fe8e67cf2ce3241753021bdea343cda14700e48731f3759)
  • Node Version: v6.14.3
  • Browser/OS: docker, firefox
  • Database: mysql:5.7

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hassan-jahancommented, Sep 6, 2019

The problem is related to docker swarm and pooling.

Disable pooling (min:0)

Or check out this: https://success.docker.com/article/ipvs-connection-timeout-issue

1reaction
macchiecommented, Nov 16, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Intermittent 500.0 Error After A Period of Inactivity - MSDN
I've created a set of anonymous access, http triggered azure functions corresponding to the pages of a website. Everything works fine most ...
Read more >
500 Internal Server Error - HTTP - MDN Web Docs - Mozilla
This error response is a generic "catch-all" response. Usually, this indicates the server cannot find a better 5xx error code to response.
Read more >
I get 500 Internal Server Error after 30 seconds of running a ...
I think you run Fast CGI. The CGI process has a maximum execution time. In fastcgi its the idle-timeout. After that you get...
Read more >
ORDS 500 Internal Server Error (SEVERE ... Java.sql ...
2 The error can occur at any time, however mostly occurs after a period of inactivity - say 10-20 minutes or more and...
Read more >
Internal server error exporting a large dataset to CSV - IBM
By default this is set to five minutes. If the database is processing the SQL and the CGI process is idle, the webserver...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found