File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const common = require ( '../common' ) ;
4+ const assert = require ( 'assert' ) ;
5+ const net = require ( 'net' ) ;
6+
7+ // Regression: setKeepAlive() silently ignored errors returned by the
8+ // underlying handle (https://github.com/nodejs/node/issues/65529).
9+ // It should throw like setTypeOfService() does, instead of reporting
10+ // success when the operation failed.
11+ if ( common . isWindows ) {
12+ common . skip ( 'keep-alive errors are treated as best-effort on Windows' ) ;
13+ } else {
14+ const server = net . createServer ( common . mustCall ( ( socket ) => {
15+ socket . end ( ) ;
16+ } ) ) ;
17+
18+ server . listen ( 0 , common . mustCall ( ( ) => {
19+ const client = net . connect ( server . address ( ) . port , common . mustCall ( ( ) => {
20+ // Make the handle report an error (EINVAL) for the keep-alive call.
21+ const originalSetKeepAlive = client . _handle . setKeepAlive ;
22+ client . _handle . setKeepAlive = ( ) => - 22 ; // UV_EINVAL
23+ try {
24+ assert . throws (
25+ ( ) => client . setKeepAlive ( true , 1000 ) ,
26+ ( err ) => {
27+ assert . strictEqual ( err . code , 'EINVAL' ) ;
28+ assert . strictEqual ( err . syscall , 'setKeepAlive' ) ;
29+ return true ;
30+ } ,
31+ ) ;
32+ } finally {
33+ client . _handle . setKeepAlive = originalSetKeepAlive ;
34+ }
35+ client . end ( ) ;
36+ server . close ( ) ;
37+ } ) ) ;
38+ } ) ) ;
39+ }
You can’t perform that action at this time.
0 commit comments