@@ -2032,17 +2032,15 @@ function sessionOnError(error) {
2032
2032
this . emit ( 'error' , error ) ;
2033
2033
}
2034
2034
2035
- // When a Socket emits an error, first try to forward it to the server
2036
- // as a socketError; failing that, forward it to the session as a
2035
+ // When a Socket emits an error, forward it to the session as a
2037
2036
// socketError; failing that, remove the listener and call destroy
2038
2037
function socketOnError ( error ) {
2039
2038
const type = this [ kSession ] && this [ kSession ] [ kType ] ;
2040
2039
debug ( `[${ sessionName ( type ) } ] server socket error: ${ error . message } ` ) ;
2041
2040
if ( kRenegTest . test ( error . message ) )
2042
2041
return this . destroy ( ) ;
2043
- if ( this [ kServer ] !== undefined && this [ kServer ] . emit ( 'socketError' , error ) )
2044
- return ;
2045
- if ( this [ kSession ] !== undefined && this [ kSession ] . emit ( 'socketError' , error ) )
2042
+ if ( this [ kSession ] !== undefined &&
2043
+ this [ kSession ] . emit ( 'socketError' , error , this ) )
2046
2044
return ;
2047
2045
this . removeListener ( 'error' , socketOnError ) ;
2048
2046
this . destroy ( error ) ;
@@ -2076,6 +2074,11 @@ function sessionOnPriority(stream, parent, weight, exclusive) {
2076
2074
this [ kServer ] . emit ( 'priority' , stream , parent , weight , exclusive ) ;
2077
2075
}
2078
2076
2077
+ function sessionOnSocketError ( error , socket ) {
2078
+ if ( this . listenerCount ( 'socketError' ) <= 1 && this [ kServer ] !== undefined )
2079
+ this [ kServer ] . emit ( 'socketError' , error , socket , this ) ;
2080
+ }
2081
+
2079
2082
function connectionListener ( socket ) {
2080
2083
debug ( '[server] received a connection' ) ;
2081
2084
const options = this [ kOptions ] || { } ;
@@ -2109,6 +2112,7 @@ function connectionListener(socket) {
2109
2112
session . on ( 'error' , sessionOnError ) ;
2110
2113
session . on ( 'stream' , sessionOnStream ) ;
2111
2114
session . on ( 'priority' , sessionOnPriority ) ;
2115
+ session . on ( 'socketError' , sessionOnSocketError ) ;
2112
2116
2113
2117
socket [ kServer ] = this ;
2114
2118
@@ -2193,27 +2197,14 @@ function setupCompat(ev) {
2193
2197
}
2194
2198
}
2195
2199
2196
- // If the socket emits an error, forward it to the session as a socketError;
2197
- // failing that, remove the listener and destroy the socket
2198
- function clientSocketOnError ( error ) {
2199
- const type = this [ kSession ] && this [ kSession ] [ kType ] ;
2200
- debug ( `[${ sessionName ( type ) } ] client socket error: ${ error . message } ` ) ;
2201
- if ( kRenegTest . test ( error . message ) )
2202
- return this . destroy ( ) ;
2203
- if ( this [ kSession ] !== undefined && this [ kSession ] . emit ( 'socketError' , error ) )
2204
- return ;
2205
- this . removeListener ( 'error' , clientSocketOnError ) ;
2206
- this . destroy ( error ) ;
2207
- }
2208
-
2209
2200
// If the session emits an error, forward it to the socket as a sessionError;
2210
2201
// failing that, destroy the session, remove the listener and re-emit the error
2211
2202
function clientSessionOnError ( error ) {
2212
2203
debug ( `client session error: ${ error . message } ` ) ;
2213
2204
if ( this [ kSocket ] !== undefined && this [ kSocket ] . emit ( 'sessionError' , error ) )
2214
2205
return ;
2215
2206
this . destroy ( ) ;
2216
- this . removeListener ( 'error' , clientSocketOnError ) ;
2207
+ this . removeListener ( 'error' , socketOnError ) ;
2217
2208
this . removeListener ( 'error' , clientSessionOnError ) ;
2218
2209
}
2219
2210
@@ -2249,7 +2240,7 @@ function connect(authority, options, listener) {
2249
2240
throw new errors . Error ( 'ERR_HTTP2_UNSUPPORTED_PROTOCOL' , protocol ) ;
2250
2241
}
2251
2242
2252
- socket . on ( 'error' , clientSocketOnError ) ;
2243
+ socket . on ( 'error' , socketOnError ) ;
2253
2244
socket . on ( 'resume' , socketOnResume ) ;
2254
2245
socket . on ( 'pause' , socketOnPause ) ;
2255
2246
socket . on ( 'drain' , socketOnDrain ) ;
0 commit comments