Skip to content

Commit 5930e4f

Browse files
authored
Merge pull request brianc#2210 from brianc/bmc/switch-to-fast-connection
Switch internals to use faster connection
2 parents 1c441d2 + 72b5f6d commit 5930e4f

File tree

9 files changed

+70
-941
lines changed

9 files changed

+70
-941
lines changed

.travis.yml

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ before_script: |
77
88
env:
99
- CC=clang CXX=clang++ npm_config_clang=1 PGUSER=postgres PGDATABASE=postgres
10-
# test w/ new faster parsing code
11-
- CC=clang CXX=clang++ npm_config_clang=1 PGUSER=postgres PGDATABASE=postgres PG_FAST_CONNECTION=true
1210

1311
node_js:
1412
- lts/dubnium
1513
- lts/erbium
1614
# node 13.7 seems to have changed behavior of async iterators exiting early on streams
1715
# if 13.8 still has this problem when it comes down I'll talk to the node team about the change
18-
# in the mean time...peg to 13.6
16+
# in the mean time...peg to 13.6
1917
- 13.6
2018
- 14
2119

2220
addons:
23-
postgresql: "10"
21+
postgresql: '10'
2422

2523
matrix:
2624
include:
@@ -42,25 +40,25 @@ matrix:
4240
4341
- node_js: lts/carbon
4442
addons:
45-
postgresql: "9.5"
43+
postgresql: '9.5'
4644
dist: precise
4745

4846
# different PostgreSQL versions on Node LTS
4947
- node_js: lts/erbium
5048
addons:
51-
postgresql: "9.3"
49+
postgresql: '9.3'
5250
- node_js: lts/erbium
5351
addons:
54-
postgresql: "9.4"
52+
postgresql: '9.4'
5553
- node_js: lts/erbium
5654
addons:
57-
postgresql: "9.5"
55+
postgresql: '9.5'
5856
- node_js: lts/erbium
5957
addons:
60-
postgresql: "9.6"
58+
postgresql: '9.6'
6159

6260
# PostgreSQL 9.2 only works on precise
6361
- node_js: lts/carbon
6462
addons:
65-
postgresql: "9.2"
63+
postgresql: '9.2'
6664
dist: precise

packages/pg-protocol/src/inbound-parser.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,21 @@ describe('PgPacketStream', function () {
210210
testForMessage(md5PasswordBuffer, expectedMD5PasswordMessage)
211211
testForMessage(SASLBuffer, expectedSASLMessage)
212212
testForMessage(SASLContinueBuffer, expectedSASLContinueMessage)
213+
214+
// this exercises a found bug in the parser:
215+
// https://github.com/brianc/node-postgres/pull/2210#issuecomment-627626084
216+
// and adds a test which is deterministic, rather than relying on network packet chunking
217+
const extendedSASLContinueBuffer = Buffer.concat([SASLContinueBuffer, Buffer.from([1, 2, 3, 4])])
218+
testForMessage(extendedSASLContinueBuffer, expectedSASLContinueMessage)
219+
213220
testForMessage(SASLFinalBuffer, expectedSASLFinalMessage)
214221

222+
// this exercises a found bug in the parser:
223+
// https://github.com/brianc/node-postgres/pull/2210#issuecomment-627626084
224+
// and adds a test which is deterministic, rather than relying on network packet chunking
225+
const extendedSASLFinalBuffer = Buffer.concat([SASLFinalBuffer, Buffer.from([1, 2, 4, 5])])
226+
testForMessage(extendedSASLFinalBuffer, expectedSASLFinalMessage)
227+
215228
testForMessage(paramStatusBuffer, expectedParameterStatusMessage)
216229
testForMessage(backendKeyDataBuffer, expectedBackendKeyDataMessage)
217230
testForMessage(readyForQueryBuffer, expectedReadyForQueryMessage)

packages/pg-protocol/src/parser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,11 @@ export class Parser {
296296
break
297297
case 11: // AuthenticationSASLContinue
298298
message.name = MessageName.authenticationSASLContinue
299-
message.data = this.reader.string(length - 4)
299+
message.data = this.reader.string(length - 8)
300300
break
301301
case 12: // AuthenticationSASLFinal
302302
message.name = MessageName.authenticationSASLFinal
303-
message.data = this.reader.string(length - 4)
303+
message.data = this.reader.string(length - 8)
304304
break
305305
default:
306306
throw new Error('Unknown authenticationOk message type ' + code)

packages/pg/lib/client.js

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ var ConnectionParameters = require('./connection-parameters')
1818
var Query = require('./query')
1919
var defaults = require('./defaults')
2020
var Connection = require('./connection')
21-
if (process.env.PG_FAST_CONNECTION) {
22-
Connection = require('./connection-fast')
23-
}
2421

2522
var Client = function (config) {
2623
EventEmitter.call(this)

packages/pg/lib/connection-fast.js

-214
This file was deleted.

0 commit comments

Comments
 (0)