Skip to content

Commit

Permalink
Lan: fix uncaught promise rejection
Browse files Browse the repository at this point in the history
The `lan` backend wasn't really dealing with concurrency of negotiating
auxiliary streams (i.e. transfers) at all.

Make a few minor modifications to correct a number of race conditions
and lost warnings.

closes #1605
  • Loading branch information
andyholmes authored and ferdnyc committed May 1, 2023
1 parent 81458e2 commit 1c18455
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/service/backends/lan.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,9 @@ var Channel = GObject.registerClass({
reject(e);
}
});
});
}).then(this._encryptClient.bind(this));

let connection = await openConnection;
connection = await this._encryptClient(connection);
const connection = await openConnection;
const source = connection.get_input_stream();

// Start the transfer
Expand Down Expand Up @@ -911,17 +910,17 @@ var Channel = GObject.registerClass({
}
}
);
});
}).then(this._encryptServer.bind(this));

// Notify the device we're ready
// Create an upload request
packet.body.payloadHash = this.checksum;
packet.payloadSize = size;
packet.payloadTransferInfo = {port: port};
this.sendPacket(new Core.Packet(packet));
const requestUpload = this.sendPacket(new Core.Packet(packet));

// Accept the connection and configure the channel
let connection = await acceptConnection;
connection = await this._encryptServer(connection);
// Request an upload stream, accept the connection and get the output
const [, connection] = await Promise.all([requestUpload,
acceptConnection]);
const target = connection.get_output_stream();

// Start the transfer
Expand Down

0 comments on commit 1c18455

Please sign in to comment.