Ask A Question

Notifications

You’re not receiving notifications from this thread.

TinyTds::Error (closed connection): when using Apache/Passenger

William Jones asked in Databases

When I start my application using Puma on port 3000 everything works as expected (no error). When I try to access the application after starting Apache, using the default port 80, I get the error "TinyTds::Error (closed connection):". The code at the point of the error is trying to read a remote MSSQL database. What could be some of the reasons that the connection is closed when using Apache/Passenger? I am using Ruby 2.5.3, Rails 5.1.6.1, Apache2 2.4.29, Ubuntu 18.4, Passenger 6.0.1, Tiny_tds 1.3.0, Activerecord-sqlserver-adapter 5.1.6.

Reply

Hey William!

Sounds like just a database connection issue. Puma may start up just fine because it doesn't care about the database.

You can more easily test the configuration by using the Rails console in production and seeing if you can query the database.

RAILS_ENV=production bundle exec rails c
> User.first

Chances are you'll just need to adjust your database.yml or if you're using ENV variables for production.

I don't know anything about TinyTDS, so if you can connect to the DB but it dies at some point, you might want to ask on their Github issues.

Reply

Hello Chris,
Thanks for the prompt response.
There is no problem connecting to the database when using just Puma. I can create, read, update and delete with no issues. When I use apache/passenger to access the application then I get the error.
When you mention 'ENV variables' can you be a little more specific? Perhaps there is something that I have not set correctly and I am ignorant of.

Regards,

Bill.

Reply

One thing to note: you would use Puma OR Passenger, but not both. Apache can proxy requests over to Puma, or you can have it send requests to Passenger. It's definitely easier to use Passenger because you don't have to have another process running.

Rails comes with Puma by default now to support web sockets in development, and you could also run Puma in production, but you have to run it as a separate background process with SystemD.

If you're using Passenger, you don't need to do that and you can just define the Server in Apache to have it load it.


When you say you have no problem connecting when using Puma, do you mean by running "rails console"?

Also can you share the full stacktrace for your error?

Reply

Hello Chris,
I am only using Puma or Passenger, definitely not both at the same time. When using Puma I start the rails server (i.e rails s -e production) from the application directory and the pages of the app display correctly showing data from the database calls made by the app. After stoping Puma (CTRL C) I start apache with the command 'sudo service apache2 start'. This starts correctly and when I try to access the app I get the "TinyTds::Error (closed connection):" displayed in the rails production log file. The log messages are shown below,

I, [2019-02-04T17:11:14.815714 #2769] INFO -- : [6933cfd7-efa5-492c-a538-87f5e04e9723] Started GET "/" for 10.2.0.137 at 2019-02-04 17:11:14 -0500
I, [2019-02-04T17:11:14.904719 #2769] INFO -- : [6933cfd7-efa5-492c-a538-87f5e04e9723] Processing by TurkeytoteController#totals as HTML
I, [2019-02-04T17:11:14.942821 #2769] INFO -- : [6933cfd7-efa5-492c-a538-87f5e04e9723] Completed 500 Internal Server Error in 38ms
F, [2019-02-04T17:11:14.943925 #2769] FATAL -- : [6933cfd7-efa5-492c-a538-87f5e04e9723]

F, [2019-02-04T17:11:14.943996 #2769] FATAL -- : [6933cfd7-efa5-492c-a538-87f5e04e9723] TinyTds::Error (closed connection):
F, [2019-02-04T17:11:14.944074 #2769] FATAL -- : [6933cfd7-efa5-492c-a538-87f5e04e9723]

F, [2019-02-04T17:11:14.944163 #2769] FATAL -- : [6933cfd7-efa5-492c-a538-87f5e04e9723] app/controllers/turkeytote_controller.rb:95:in get_totals'
[6933cfd7-efa5-492c-a538-87f5e04e9723] app/controllers/turkeytote_controller.rb:76:in
totals'

I am not sure how to produce a full stacktrace, any advice would be welcome.

Thanks for all your help.

Regards,

Bill.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.