File tree 4 files changed +43
-2
lines changed
4 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -359,7 +359,8 @@ impl Client {
359
359
// Clean up the server and re-use it.
360
360
// This prevents connection thrashing by bad clients.
361
361
if server. in_transaction ( ) {
362
- server. query ( "ROLLBACK; DISCARD ALL;" ) . await ?;
362
+ server. query ( "ROLLBACK" ) . await ?;
363
+ server. query ( "DISCARD ALL" ) . await ?;
363
364
}
364
365
365
366
return Err ( err) ;
@@ -429,7 +430,8 @@ impl Client {
429
430
// Pgbouncer closes the connection which leads to
430
431
// connection thrashing when clients misbehave.
431
432
if server. in_transaction ( ) {
432
- server. query ( "ROLLBACK; DISCARD ALL;" ) . await ?;
433
+ server. query ( "ROLLBACK" ) . await ?;
434
+ server. query ( "DISCARD ALL" ) . await ?;
433
435
}
434
436
435
437
return Ok ( ( ) ) ;
Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ source "https://rubygems.org"
2
2
3
3
gem "pg"
4
4
gem "activerecord"
5
+ gem "rubocop"
Original file line number Diff line number Diff line change 11
11
i18n (>= 1.6 , < 2 )
12
12
minitest (>= 5.1 )
13
13
tzinfo (~> 2.0 )
14
+ ast (2.4.2 )
14
15
concurrent-ruby (1.1.9 )
15
16
i18n (1.10.0 )
16
17
concurrent-ruby (~> 1.0 )
17
18
minitest (5.15.0 )
19
+ parallel (1.22.1 )
20
+ parser (3.1.2.0 )
21
+ ast (~> 2.4.1 )
18
22
pg (1.3.2 )
23
+ rainbow (3.1.1 )
24
+ regexp_parser (2.3.1 )
25
+ rexml (3.2.5 )
26
+ rubocop (1.29.0 )
27
+ parallel (~> 1.10 )
28
+ parser (>= 3.1.0.0 )
29
+ rainbow (>= 2.2.2 , < 4.0 )
30
+ regexp_parser (>= 1.8 , < 3.0 )
31
+ rexml (>= 3.2.5 , < 4.0 )
32
+ rubocop-ast (>= 1.17.0 , < 2.0 )
33
+ ruby-progressbar (~> 1.7 )
34
+ unicode-display_width (>= 1.4.0 , < 3.0 )
35
+ rubocop-ast (1.17.0 )
36
+ parser (>= 3.1.1.0 )
37
+ ruby-progressbar (1.11.0 )
19
38
tzinfo (2.0.4 )
20
39
concurrent-ruby (~> 1.0 )
40
+ unicode-display_width (2.1.0 )
21
41
22
42
PLATFORMS
23
43
x86_64-linux
24
44
25
45
DEPENDENCIES
26
46
activerecord
27
47
pg
48
+ rubocop
28
49
29
50
BUNDLED WITH
30
51
2.3.7
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require 'active_record'
4
+ require 'pg'
5
+
6
+ $stdout. sync = true
4
7
5
8
# Uncomment these two to see all queries.
6
9
# ActiveRecord.verbose_query_logs = true
@@ -110,3 +113,17 @@ def down
110
113
rescue ActiveRecord ::StatementInvalid
111
114
puts 'OK'
112
115
end
116
+
117
+ # Test evil clients
118
+ def poorly_behaved_client
119
+ conn = PG ::connect ( "postgres://sharding_user:sharding_user@127.0.0.1:6432/rails_dev" )
120
+ conn . async_exec 'BEGIN'
121
+ conn . async_exec 'SELECT 1'
122
+
123
+ conn . close
124
+ puts 'Bad client ok'
125
+ end
126
+
127
+ 25 . times do
128
+ poorly_behaved_client
129
+ end
You can’t perform that action at this time.
0 commit comments