Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7105 (closed defect: fixed)

Opened 2 years ago

Last modified 2 months ago

[PATCH] "Too many open files" with sqlite3 driver in development mode

Reported by: rob.rasmussen Assigned to: core
Priority: normal Milestone: 1.2
Component: ActiveRecord Version: edge
Severity: normal Keywords: sqlite
Cc:

Description

We moved to edge rails last week, and have been seeing our Rails app crash with "Too many open files" after the app runs awhile in development mode. After some investigation, we found that the culprit is open filehandles pointing to our sqlite3 database (I'll attach a screenshot showing you what I mean). This only occurs in dev mode, and we essentially end up with an open filehandle per request.

So, we went looking at Dispatcher.reset_application! and discovered that commenting out ActiveRecord::Base.clear_reloadable_connections! made the problem go away. After looking further, we found that adding:

def disconnect!

@connection.close rescue nil

end

to sqlite_adapter.rb caused the driver to release the file handle and fixed the problem.

This is an easily reproducible problem, at least on OS X. I can provide a sample project if necessary.

Attachments

close_sqlite_connections_on_disconnect.diff (0.6 kB) - added by rob.rasmussen on 01/17/07 00:28:16.
sqlite3_open_database_files.tiff (56.4 kB) - added by rob.rasmussen on 01/17/07 00:28:45.
close_sqlite_connection_on_disconnect2.diff (0.6 kB) - added by rob.rasmussen on 01/17/07 01:05:17.
close_sqlite_connections_on_disconnect3.diff (0.6 kB) - added by rob.rasmussen on 01/17/07 02:20:24.

Change History

01/17/07 00:28:16 changed by rob.rasmussen

  • attachment close_sqlite_connections_on_disconnect.diff added.

01/17/07 00:28:45 changed by rob.rasmussen

  • attachment sqlite3_open_database_files.tiff added.

(follow-up: ↓ 2 ) 01/17/07 00:44:30 changed by manfred

Was this on a checkout from a week ago? Because there were some fixes in the connection code for SQLite the last few days.

(in reply to: ↑ 1 ) 01/17/07 00:51:30 changed by rob.rasmussen

No, reproducible from the trunk.

01/17/07 01:05:17 changed by rob.rasmussen

  • attachment close_sqlite_connection_on_disconnect2.diff added.

01/17/07 01:06:53 changed by rob.rasmussen

I just realized the patch I sent was against RC2, new patch is against trunk. Sorry about that.

01/17/07 02:20:24 changed by rob.rasmussen

  • attachment close_sqlite_connections_on_disconnect3.diff added.

01/17/07 02:21:45 changed by rob.rasmussen

attached a new patch that passes AR tests

01/17/07 02:35:07 changed by rob.rasmussen

  • version set to edge.

01/22/07 23:07:54 changed by minam

  • status changed from new to closed.
  • resolution set to fixed.

(In [6012]) Make sure sqlite3 driver closes open connections on disconnect (closes #7105)

08/05/08 12:41:29 changed by alpha

I had the same problem and fixed it in a similar way before I found this ticket. The problem is easier to reproduce on OS X because it has a default maximum of 256 file descriptors.