Search code examples
rubysinatravagrantchef-infrasinatra-assetpack

sinatra app stalls in production mode when deployed via vagrant to a VM and provisioned by varnish and run as a deamon


I have a sinatra app, when I run it in production it acts odly.

The first requests works, assets download and the page loads. If you refresh the page however the request just stalls, and nothing gets logged out to the log file.

I'm running with sinatra-asset-pack and I did precompile the assets before starting it.

I'd post code but I'm not sure what would be needed to work out the issue

EDIT: it works fine on my own box, but when I deploy it to a VM using vagrant it just ceases up in production mode, it's fine in development mode though.

EDIT: I was able to get it to spit out this error:

Errno::EPIPE Broken pipe @ io_write -

And narrow it down to an action, however posting the code in the action is pointless as it doesn't log anything out and the first line of the action is a logging action so I'm not sure the action gets run at all; the logging was added after the problem hit so whatever it is, I don't think it's that.

EDIT: the error actually occurs here (base.rb(1144) of sinatra:

1142 def dump_errors!(boom)
1143  msg = ["#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{boom.class} - #{boom.message}:", *boom.backtrace].join("\n\t")
1144  @env['rack.errors'].puts(msg)
1145 end

EDIT: Ok, so when I run the deployment command manually it works fine; weirdly the output from the server is still being outputted to the terminal despite it being forked, I wonder if that's the problem. The broken pipe is the terminal that no-longer exists (when deployed via chef) and as such it's breaking... maybe?


Solution

  • Ok, turns out that the broken pipe thing was the cause, for some reason even after being forked it was trying to write stdout and stderr to the terminal. However because the terminal no longer existed (It's started by chef) it could no longer write to the output and thus locked up, starting the app manually on the VM allowed it to work and further evidence to this conclusion is that adding a redirect (>> app.log 2>&1) to the end of the start command allowed the app to work.

    Why sinatra is still writing logs to the terminal instead of the file I don't know and I need to work that out, but the main issue of the why is solved.

    EDIT:

    In the end I'm just doing this:

    $stderr = @log.file
    $stdout = @log.file
    

    to redirect it to the same place as my logs go so it should be fine now... I think?