File tree Expand file tree Collapse file tree 3 files changed +41
-10
lines changed
test/integration/connection Expand file tree Collapse file tree 3 files changed +41
-10
lines changed Original file line number Diff line number Diff line change @@ -68,10 +68,10 @@ ClientHandshake.prototype.calculateNativePasswordAuthToken = function (authPlugi
68
68
ClientHandshake . prototype . handshakeInit = function ( helloPacket , connection ) {
69
69
var command = this ;
70
70
71
- this . on ( 'error' , function ( err ) {
72
- connection . _protocolError = err ;
73
- connection . emit ( 'error' , err ) ;
71
+ this . on ( 'error' , function ( e ) {
72
+ connection . _protocolError = e ;
74
73
} ) ;
74
+
75
75
this . handshake = Packets . Handshake . fromPacket ( helloPacket ) ;
76
76
if ( connection . config . debug ) {
77
77
console . log ( 'Server hello packet: capability flags:%d=(%s)' , this . handshake . capabilityFlags ,
Original file line number Diff line number Diff line change @@ -103,19 +103,17 @@ function Connection (opts)
103
103
return ;
104
104
}
105
105
106
- // TODO: move to protocolError()
107
106
if ( ! connection . _protocolError ) { // no particular error message before disconnect
108
- connection . _protocolError = 'PROTOCOL_CONNECTION_LOST' ;
107
+ connection . _protocolError = new Error ( 'Connection lost: The server closed the connection.' ) ;
108
+ connection . _protocolError . fatal = true ;
109
+ connection . _protocolError . code = 'PROTOCOL_CONNECTION_LOST' ;
109
110
}
110
- var err = new Error ( 'Connection lost: The server closed the connection.' ) ;
111
- err . fatal = true ;
112
- err . code = connection . _protocolError ;
113
- connection . _notifyError ( err ) ;
111
+
112
+ connection . _notifyError ( connection . _protocolError ) ;
114
113
} ) ;
115
114
var handshakeCommand ;
116
115
if ( ! this . config . isServer ) {
117
116
handshakeCommand = new Commands . ClientHandshake ( this . config . clientFlags ) ;
118
- handshakeCommand . on ( 'error' , function ( e ) { connection . emit ( 'error' , e ) ; } ) ;
119
117
handshakeCommand . on ( 'end' , function ( ) {
120
118
connection . _handshakePacket = handshakeCommand . handshake ;
121
119
connection . threadId = handshakeCommand . handshake . connectionId ;
Original file line number Diff line number Diff line change
1
+ var common = require ( '../../common' ) ;
2
+ var assert = require ( 'assert' ) ;
3
+
4
+ var callCount = 0 ;
5
+ var exceptionCount = 0 ;
6
+
7
+ process . on ( 'uncaughtException' , function ( err ) {
8
+ assert . ifError ( err ) ;
9
+ exceptionCount ++ ;
10
+ } ) ;
11
+
12
+ var connection1 = common . createConnection ( {
13
+ password : 'lol'
14
+ } ) ;
15
+
16
+ // error will NOT bubble up to process level if `on` is used
17
+ connection1 . on ( 'error' , function ( ) {
18
+ callCount ++ ;
19
+ } ) ;
20
+
21
+ var connection2 = common . createConnection ( {
22
+ password : 'lol'
23
+ } ) ;
24
+
25
+ // error will bubble up to process level if `once` is used
26
+ connection2 . once ( 'error' , function ( ) {
27
+ callCount ++ ;
28
+ } ) ;
29
+
30
+ process . on ( 'exit' , function ( ) {
31
+ assert . equal ( callCount , 2 ) ;
32
+ assert . equal ( exceptionCount , 0 ) ;
33
+ } ) ;
You can’t perform that action at this time.
0 commit comments