Skip to content

Commit

Permalink
fix: check writableNeedDrain to fix memory leak after writing data wi…
Browse files Browse the repository at this point in the history
…th false result

Signed-off-by: haiyan.tan <[email protected]>
  • Loading branch information
harlentan authored and haiyan.tan committed Jan 3, 2025
1 parent 37c09d2 commit 612ade5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/adb/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ export default class Connection extends EventEmitter {
return this;
}

public write(data: Buffer, callback?: (err?: Error) => void): boolean {
return this.socket.write(dump(data), callback);
public write(data: Buffer, callback?: (err?: Error) => void): this {
this.socket.write(dump(data), callback);
return this;
}

public startServer(): Bluebird<ChildProcess> {
Expand Down
2 changes: 1 addition & 1 deletion src/adb/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default class Sync extends EventEmitter {
if (!this.connection.socket.writableNeedDrain && (chunk = stream.read(DATA_MAX_LENGTH) || stream.read())) {
this._sendCommandWithLength(Protocol.DATA, chunk.length);
transfer.push(chunk.length);
if (this.connection.write(chunk, track)) {
if (!this.connection.write(chunk, track).socket.writableNeedDrain) {
return writeNext();
} else {
return waitForDrain().then(writeNext);
Expand Down

0 comments on commit 612ade5

Please sign in to comment.