{"action":"created","issue":{"url":"https://api.github.com/repos/igrigorik/em-synchrony/issues/190","labels_url":"https://api.github.com/repos/igrigorik/em-synchrony/issues/190/labels{/name}","comments_url":"https://api.github.com/repos/igrigorik/em-synchrony/issues/190/comments","events_url":"https://api.github.com/repos/igrigorik/em-synchrony/issues/190/events","html_url":"https://github.com/igrigorik/em-synchrony/pull/190","id":57214433,"number":190,"title":"Fiber aware support for ActiveRecord 4","user":{"login":"marshall-lee","id":3194530,"avatar_url":"https://avatars.githubusercontent.com/u/3194530?v=3","gravatar_id":"","url":"https://api.github.com/users/marshall-lee","html_url":"https://github.com/marshall-lee","followers_url":"https://api.github.com/users/marshall-lee/followers","following_url":"https://api.github.com/users/marshall-lee/following{/other_user}","gists_url":"https://api.github.com/users/marshall-lee/gists{/gist_id}","starred_url":"https://api.github.com/users/marshall-lee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marshall-lee/subscriptions","organizations_url":"https://api.github.com/users/marshall-lee/orgs","repos_url":"https://api.github.com/users/marshall-lee/repos","events_url":"https://api.github.com/users/marshall-lee/events{/privacy}","received_events_url":"https://api.github.com/users/marshall-lee/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-02-10T18:23:48Z","updated_at":"2015-03-18T10:38:13Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/igrigorik/em-synchrony/pulls/190","html_url":"https://github.com/igrigorik/em-synchrony/pull/190","diff_url":"https://github.com/igrigorik/em-synchrony/pull/190.diff","patch_url":"https://github.com/igrigorik/em-synchrony/pull/190.patch"},"body":"Hello!\r\nI took https://github.com/igrigorik/em-synchrony/pull/179 and added support for ActiveRecord 4.\r\nAll ActiveRecord specs are green for stable versions of 3.2, 4.0, 4.1 and 4.2.\r\n\r\nAlso I reimplemented `clear_stale_cached_connections!` for 3.2 that could help but not so much. ActiveRecord users should explicitly release connections or `ActiveRecord::ConnectionAdapters::ConnectionManagement` middleware could do this and there is nothing to do with it. By the way, they should do it in threaded environment too. Anyway.\r\n\r\n3.1 is not working and I cannot figure out why. So my opinion: we should drop 3.1 support in favor of better implementation for >= 3.2, < 5.\r\n\r\nCurrently tests may fail because of broken `mysql2`. See https://github.com/brianmario/mysql2/pull/580 (with specs) or https://github.com/brianmario/mysql2/pull/509 — with any of these patches everything works great."},"comment":{"url":"https://api.github.com/repos/igrigorik/em-synchrony/issues/comments/82887742","html_url":"https://github.com/igrigorik/em-synchrony/pull/190#issuecomment-82887742","issue_url":"https://api.github.com/repos/igrigorik/em-synchrony/issues/190","id":82887742,"user":{"login":"marshall-lee","id":3194530,"avatar_url":"https://avatars.githubusercontent.com/u/3194530?v=3","gravatar_id":"","url":"https://api.github.com/users/marshall-lee","html_url":"https://github.com/marshall-lee","followers_url":"https://api.github.com/users/marshall-lee/followers","following_url":"https://api.github.com/users/marshall-lee/following{/other_user}","gists_url":"https://api.github.com/users/marshall-lee/gists{/gist_id}","starred_url":"https://api.github.com/users/marshall-lee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marshall-lee/subscriptions","organizations_url":"https://api.github.com/users/marshall-lee/orgs","repos_url":"https://api.github.com/users/marshall-lee/repos","events_url":"https://api.github.com/users/marshall-lee/events{/privacy}","received_events_url":"https://api.github.com/users/marshall-lee/received_events","type":"User","site_admin":false},"created_at":"2015-03-18T10:38:13Z","updated_at":"2015-03-18T10:38:13Z","body":"This is the 'official' behaviour of ActiveRecord.\r\n\r\nActiveRecord 4.1, multithreaded, with `Acticonnection_pool.size == 5`:\r\n\r\n```ruby\r\n    threads = []\r\n    10.times do\r\n      threads << Thread.new do\r\n        ActiveRecord::Base.connection.execute(\"select 1\")\r\n      end\r\n    end\r\n    threads.each(&:join)\r\n```\r\n\r\n— this one stucks\r\n\r\n```ruby\r\n    threads = []\r\n    10.times do\r\n      threads << Thread.new do\r\n        ActiveRecord::Base.connection.execute(\"select 1\")\r\n        ActiveRecord::Base.clear_active_connections!\r\n      end\r\n    end\r\n    threads.each(&:join)\r\n```\r\n\r\n— this one doesn't, because we *release* connection acquired by current thread.\r\n\r\n```ruby\r\n    threads = []\r\n    10.times do\r\n      threads << Thread.new do\r\n        ActiveRecord::Base.connection.execute(\"select 1\")\r\n        ActiveRecord::Base.connection.close\r\n      end\r\n    end\r\n    threads.each(&:join)\r\n```\r\n\r\n— this one doesn't stuck too, because after *closing* and terminating the acquiring thread, connection  became *stale* so it can be reacquired by other thread."}}