Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c81a74c9
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c81a74c9
编写于
12月 23, 2014
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18167 from al2o3cr/checkin_connection_leak
Fix connection leak when a thread checks in additional connections.
上级
21289bed
5e024070
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
4 deletion
+36
-4
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
...ve_record/connection_adapters/abstract/connection_pool.rb
+6
-4
activerecord/test/cases/pooled_connections_test.rb
activerecord/test/cases/pooled_connections_test.rb
+30
-0
未找到文件。
activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
浏览文件 @
c81a74c9
...
...
@@ -363,7 +363,7 @@ def checkin(conn)
conn
.
expire
end
release
owner
release
conn
,
owner
@available
.
add
conn
end
...
...
@@ -376,7 +376,7 @@ def remove(conn)
@connections
.
delete
conn
@available
.
delete
conn
release
conn
.
owner
release
conn
,
conn
.
owner
@available
.
add
checkout_new_connection
if
@available
.
any_waiting?
end
...
...
@@ -424,10 +424,12 @@ def acquire_connection
end
end
def
release
(
owner
)
def
release
(
conn
,
owner
)
thread_id
=
owner
.
object_id
@reserved_connections
.
delete
thread_id
if
@reserved_connections
[
thread_id
]
==
conn
@reserved_connections
.
delete
thread_id
end
end
def
new_connection
...
...
activerecord/test/cases/pooled_connections_test.rb
浏览文件 @
c81a74c9
...
...
@@ -35,6 +35,22 @@ def checkout_checkin_connections(pool_size, threads)
end
end
def
checkout_checkin_connections_loop
(
pool_size
,
loops
)
ActiveRecord
::
Base
.
establish_connection
(
@connection
.
merge
({
:pool
=>
pool_size
,
:checkout_timeout
=>
0.5
}))
@connection_count
=
0
@timed_out
=
0
loops
.
times
do
begin
conn
=
ActiveRecord
::
Base
.
connection_pool
.
checkout
ActiveRecord
::
Base
.
connection_pool
.
checkin
conn
@connection_count
+=
1
ActiveRecord
::
Base
.
connection
.
tables
rescue
ActiveRecord
::
ConnectionTimeoutError
@timed_out
+=
1
end
end
end
def
test_pooled_connection_checkin_one
checkout_checkin_connections
1
,
2
assert_equal
2
,
@connection_count
...
...
@@ -42,6 +58,20 @@ def test_pooled_connection_checkin_one
assert_equal
1
,
ActiveRecord
::
Base
.
connection_pool
.
connections
.
size
end
def
test_pooled_connection_checkin_two
checkout_checkin_connections_loop
2
,
3
assert_equal
3
,
@connection_count
assert_equal
0
,
@timed_out
assert_equal
2
,
ActiveRecord
::
Base
.
connection_pool
.
connections
.
size
end
def
test_pooled_connection_remove
ActiveRecord
::
Base
.
establish_connection
(
@connection
.
merge
({
:pool
=>
2
,
:checkout_timeout
=>
0.5
}))
old_connection
=
ActiveRecord
::
Base
.
connection
extra_connection
=
ActiveRecord
::
Base
.
connection_pool
.
checkout
ActiveRecord
::
Base
.
connection_pool
.
remove
(
extra_connection
)
assert_equal
ActiveRecord
::
Base
.
connection
,
old_connection
end
private
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录