Skip to content

Commit 612ade5

Browse files
harlentanhaiyan.tan
authored andcommitted
fix: check writableNeedDrain to fix memory leak after writing data with false result
Signed-off-by: haiyan.tan <haiyan.tan@alibaba-inc.com>
1 parent 37c09d2 commit 612ade5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/adb/connection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ export default class Connection extends EventEmitter {
7878
return this;
7979
}
8080

81-
public write(data: Buffer, callback?: (err?: Error) => void): boolean {
82-
return this.socket.write(dump(data), callback);
81+
public write(data: Buffer, callback?: (err?: Error) => void): this {
82+
this.socket.write(dump(data), callback);
83+
return this;
8384
}
8485

8586
public startServer(): Bluebird<ChildProcess> {

src/adb/sync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export default class Sync extends EventEmitter {
191191
if (!this.connection.socket.writableNeedDrain && (chunk = stream.read(DATA_MAX_LENGTH) || stream.read())) {
192192
this._sendCommandWithLength(Protocol.DATA, chunk.length);
193193
transfer.push(chunk.length);
194-
if (this.connection.write(chunk, track)) {
194+
if (!this.connection.write(chunk, track).socket.writableNeedDrain) {
195195
return writeNext();
196196
} else {
197197
return waitForDrain().then(writeNext);

0 commit comments

Comments
 (0)