Scheduling cause an InternalServerError

coming here from a github referece
would very much appreciate your help :)

Hi Team!
we’ve recently upgraded to 2.31 (and we love it)
our stack is using nginx (as a reverse proxy) on the server and we’re runing ghost from it’s official docker image

everything is working great except the scheduling option which yield the following logs

_Error ID:
    cafae0d0-dad1-11e9-b54c-dde50bb34d18

----------------------------------------

InternalServerError: The server has encountered an error.
    at new GhostError (/var/lib/ghost/versions/2.31.0/core/server/lib/common/errors.js:10:26)
    at request.catch (/var/lib/ghost/versions/2.31.0/core/server/adapters/scheduling/SchedulingDefault.js:349:30)
    at tryCatcher (/var/lib/ghost/versions/2.31.0/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/var/lib/ghost/versions/2.31.0/node_modules/bluebird/js/release/promise.js:517:31)
    at Promise._settlePromise (/var/lib/ghost/versions/2.31.0/node_modules/bluebird/js/release/promise.js:574:18)
    at Promise._settlePromise0 (/var/lib/ghost/versions/2.31.0/node_modules/bluebird/js/release/promise.js:619:10)
    at Promise._settlePromises (/var/lib/ghost/versions/2.31.0/node_modules/bluebird/js/release/promise.js:695:18)
    at _drainQueueStep (/var/lib/ghost/versions/2.31.0/node_modules/bluebird/js/release/async.js:138:12)
    at _drainQueue (/var/lib/ghost/versions/2.31.0/node_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/var/lib/ghost/versions/2.31.0/node_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/var/lib/ghost/versions/2.31.0/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:126:23)

HTTPError: Response code 301 (Moved Permanently)
    at EventEmitter.emitter.on (/var/lib/ghost/versions/2.31.0/node_modules/got/source/as-pro_

the nginx logs show also this call

nginx.1    | <my site> 172.17.0.1 - - [20/Sep/2019:23:18:59 +0000] "PUT /ghost/api/v0.1/schedules/posts/5d85573bd59d65000127d103?client_id=ghost-scheduler&client_secret=<my secret> HTTP/1.1" 301 178 "-" "Ghost/2.31.0 (https://github.com/TryGhost/Ghost)"

also accessing the resource manually (with a browser) yield :

{
"errors": [
{
"message": "Resource not found",
"errorType": "NotFoundError"
}
]
}

To Reproduce

  1. install ghost with docker
docker run -d --name my-ghost \
                        --restart always \
                        -p 3002:2368 \
                        -e 'VIRTUAL_HOST=<my domain>' \
                        -e 'VIRTUAL_PORT=3002' \
                        -e 'NODE_ENV=production' \
                        -e 'url=<my url>' \
                        ghost:2.31.0-alpine
  1. configure nginx
    server {
        server_name         <your domain>;
        listen              80;
        location / {
            proxy_pass http://localhost:3002/;
        }
    }

Any other info e.g. Why do you consider this to be a bug? What did you expect to happen instead?

Technical details:

  • Ghost Version: 2.31.0
  • Node Version: v6.11.2
  • Browser/OS: -
  • Database: SQLite Database

At first glance, it looks like the HTTP request sent to the API to publish your post gets redirected, which suggests your URL is possibly misconfigured.

To be clear, publishing a post triggers an HTTP PUT request to the API - that’s what you see in your nginx logs. You can see it 301s, which is not normal for a PUT request. Ghost doesn’t know what to do with this, hence the error.

It’d be much easier to debug if you could share your URL, otherwise, hopefully this explains what’s happening enough to debug it.

hi, @Hannah thanks a lot for taking the time to explain how the scheduling process works.

It’d be much easier to debug if you could share your URL, otherwise, hopefully this explains what’s happening enough to debug it.

absolutely no problem, its: https://wods.crossfitpanda.com

@Hannah and here’s the run script for ghost docker

docker run -d --name crossfitpanda-ghost \
                        --restart always \
                        -p 3002:2368 \
                        -e 'VIRTUAL_HOST=wods.crossfitpanda.com' \
                        -e 'VIRTUAL_PORT=3002' \
                        -e 'NODE_ENV=production' \
                        -e 'url=https://wods.crossfitpanda.com' \
                        -v /home/ghost/:/var/lib/ghost/content \
                        -e NODE_ENV=production \
                        -e url=http://wods.crossfitpanda.com \
                        ghost:2.31.0-alpine

You’ve got some duplicated flags in that docker command:

 -e 'NODE_ENV=production' \
-e 'url=https://wods.crossfitpanda.com' \
-v /home/ghost/:/var/lib/ghost/content \
-e NODE_ENV=production \
-e url=http://wods.crossfitpanda.com \

The first one URL https, the second is http. Setting your url to be http would probably cause this problem, but as I see it your site is currently correctly configured to https (all the urls output by ghost_head are correctly https).

I wonder if docker is inconsistent in which url variable gets used :thinking:

Is the problem still happening? Can you reproduce getting a 301 if you run:

curl -X PUT http://wods.crossfitpanda.com/ghost/api/v0.1/schedules/posts/5d85573bd59d65000127d103?client_id=ghost-scheduler&client_secret=YOUR_SECRET

or

curl -X PUT https://wods.crossfitpanda.com/ghost/api/v0.1/schedules/posts/5d85573bd59d65000127d103?client_id=ghost-scheduler&client_secret=YOUR_SECRET

(note the only difference is http and https)

I get a 401 as expected because I don’t have the right secret.

DUH!

it does seems to be an issues. I’m not sure why would ghost take the second string for scheduling.
I’ve started to check the source.

post-scheduling.js is initialized with a schedulerUrl

anyways the scheduler seems to work! @Hannah == :angel: , thanks again!