File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,12 @@ class DuplexSocket extends Duplex {
2020 }
2121
2222 _write ( chunk , encoding , callback ) {
23- this [ kOtherSide ] [ kCallback ] = callback ;
24- this [ kOtherSide ] . push ( chunk ) ;
23+ if ( chunk . length ) {
24+ this [ kOtherSide ] [ kCallback ] = callback ;
25+ this [ kOtherSide ] . push ( chunk ) ;
26+ } else {
27+ callback ( ) ;
28+ }
2529 }
2630
2731 _final ( callback ) {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ const DuplexPair = require('../');
44const assert = require ( 'assert' ) ;
55
66describe ( 'DuplexPair' , function ( ) {
7- it ( 'passed data through' , function ( ) {
7+ it ( 'passes data through' , function ( ) {
88 const pair = new DuplexPair ( { encoding : 'utf8' } ) ;
99 pair . socket1 . write ( 'Hello' ) ;
1010 assert . strictEqual ( pair . socket1 . read ( ) , null ) ;
@@ -18,4 +18,24 @@ describe('DuplexPair', function() {
1818 pair . socket2 . end ( ) ;
1919 assert . strictEqual ( pair . socket1 . read ( ) , null ) ;
2020 } ) ;
21+
22+ it ( 'does not deadlock when writing empty chunks' , function ( done ) {
23+ const pair = new DuplexPair ( { encoding : 'utf8' } ) ;
24+
25+ pair . socket2 . resume ( ) ;
26+ pair . socket2 . on ( 'end' , function ( ) {
27+ pair . socket2 . write ( 'Hello' ) ;
28+ pair . socket2 . write ( '' ) ;
29+ pair . socket2 . end ( ) ;
30+ } ) ;
31+
32+ pair . socket1 . on ( 'data' , function ( chunk ) {
33+ assert . strictEqual ( chunk , 'Hello' ) ;
34+ } ) ;
35+ pair . socket1 . on ( 'end' , function ( ) {
36+ done ( ) ;
37+ } ) ;
38+
39+ pair . socket1 . end ( ) ;
40+ } ) ;
2141} ) ;
You can’t perform that action at this time.
0 commit comments