Chromium Code Reviews| Index: net/quic/chromium/quic_chromium_client_session.cc |
| diff --git a/net/quic/chromium/quic_chromium_client_session.cc b/net/quic/chromium/quic_chromium_client_session.cc |
| index 258b0c6b4eac7cfb2498a95f5b29fc00dbc2a388..8d6f81d8fb8d0038e0672827ac23469c4210f894 100644 |
| --- a/net/quic/chromium/quic_chromium_client_session.cc |
| +++ b/net/quic/chromium/quic_chromium_client_session.cc |
| @@ -237,8 +237,7 @@ QuicChromiumClientSession::QuicChromiumClientSession( |
| token_binding_signatures_(kTokenBindingSignatureMapSize), |
| streams_pushed_count_(0), |
| streams_pushed_and_claimed_count_(0), |
| - error_code_from_rewrite_(OK), |
| - use_error_code_from_rewrite_(false), |
| + packet_(nullptr), |
|
Ryan Hamilton
2016/09/10 16:29:47
nit: no need for this as the default constructor w
Jana
2016/09/10 23:08:31
Done.
|
| weak_factory_(this) { |
| sockets_.push_back(std::move(socket)); |
| packet_readers_.push_back(base::WrapUnique(new QuicChromiumPacketReader( |
| @@ -952,11 +951,61 @@ int QuicChromiumClientSession::HandleWriteError( |
| int error_code, |
| scoped_refptr<StringIOBuffer> packet) { |
| DCHECK(packet != nullptr); |
| - use_error_code_from_rewrite_ = false; |
| - if (stream_factory_) { |
| - stream_factory_->MaybeMigrateSingleSession(this, WRITE_ERROR, packet); |
| + DCHECK_NE(ERR_IO_PENDING, error_code); |
| + DCHECK_GT(0, error_code); |
| + |
| + // Post a task to migrate the session onto a new network. |
| + task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&QuicChromiumClientSession::MigrateSessionOnWriteError, |
| + weak_factory_.GetWeakPtr())); |
| + |
| + // Store packet in the session since the actual migration and packet rewrite |
| + // can happen via this posted task or via an async network notification. |
| + packet_ = packet; |
| + |
| + // Cause the packet writer to return ERR_IO_PENDING and block so |
| + // that there are no write errors due to subsequent writes while the |
| + // session tries migrating to a new writer/socket. |
|
Ryan Hamilton
2016/09/10 16:29:46
Since the actual write happen after yet another Po
Jana
2016/09/10 23:08:30
Much more accurate -- done.
|
| + return ERR_IO_PENDING; |
| +} |
| + |
| +void QuicChromiumClientSession::MigrateSessionOnWriteError() { |
| + if (packet_ == nullptr) |
| + // If packet_ no longer exists, it must have been written on a |
| + // different migration attempt. Do not attempt another migration. |
|
Ryan Hamilton
2016/09/10 16:29:46
nit: As written, the body of this if is 3 lines lo
Jana
2016/09/10 23:08:30
I assumed that comments didn't count. It's about r
|
| + return; |
| + |
| + if (stream_factory_ != nullptr && |
| + stream_factory_->MaybeMigrateSingleSession(this, WRITE_ERROR) == |
| + MigrationResult::SUCCESS) |
| + return; |
| + |
| + // Close the connection if migration failed. Do not cause a |
| + // connection close packet to be sent since socket may be borked. |
| + connection()->CloseConnection(QUIC_PACKET_WRITE_ERROR, |
| + "Write and subsequent migration failed", |
| + ConnectionCloseBehavior::SILENT_CLOSE); |
| +} |
| + |
| +void QuicChromiumClientSession::WriteToNewSocket( |
| + scoped_refptr<StringIOBuffer> packet) { |
| + if (packet == nullptr) { |
| + connection()->SendPing(); |
| + return; |
| + } |
|
Ryan Hamilton
2016/09/10 16:29:46
Under what circumstances is this code path hit? Ca
Jana
2016/09/10 23:08:31
You're partially right that you can hit this code
Jana
2016/09/11 05:30:46
Ok, I've simplified and removed the possibility of
|
| + WriteResult result = |
|
Ryan Hamilton
2016/09/10 16:29:46
Let's add a comment here to explain that the conne
Jana
2016/09/10 23:08:30
Done.
|
| + static_cast<QuicChromiumPacketWriter*>(connection()->writer()) |
| + ->WritePacketToSocket(packet); |
| + |
| + // If write completes synchronously, notify the connection. The writer |
| + // notifies the connection on async completions. |
| + if (result.error_code < 0 && result.error_code != ERR_IO_PENDING) { |
| + connection()->OnWriteError(result.error_code); |
|
Ryan Hamilton
2016/09/10 16:29:47
In theory, we should never get a WriteError becaus
Jana
2016/09/10 23:08:31
Correct. I see this in the tests on multiple write
|
| + return; |
| } |
| - return use_error_code_from_rewrite_ ? error_code_from_rewrite_ : error_code; |
| + if (result.error_code != ERR_IO_PENDING) |
| + connection()->OnCanWrite(); |
|
Ryan Hamilton
2016/09/10 16:29:47
nit: how about
if (result.error_code == ERR_IO_PE
Jana
2016/09/10 23:08:31
Done. I have a mild preference for it to stay here
|
| } |
| void QuicChromiumClientSession::OnWriteError(int error_code) { |
| @@ -971,7 +1020,7 @@ void QuicChromiumClientSession::OnWriteUnblocked() { |
| void QuicChromiumClientSession::OnPathDegrading() { |
| if (stream_factory_) { |
| - stream_factory_->MaybeMigrateSingleSession(this, EARLY_MIGRATION, nullptr); |
| + stream_factory_->MaybeMigrateSingleSession(this, EARLY_MIGRATION); |
|
Ryan Hamilton
2016/09/10 16:29:47
Is it possible that this is called while a write i
Jana
2016/09/10 23:08:31
This should be handled in the same way as NCN-migr
|
| } |
| } |
| @@ -1178,25 +1227,28 @@ void QuicChromiumClientSession::NotifyFactoryOfSessionClosed() { |
| bool QuicChromiumClientSession::MigrateToSocket( |
| std::unique_ptr<DatagramClientSocket> socket, |
| std::unique_ptr<QuicChromiumPacketReader> reader, |
| - std::unique_ptr<QuicChromiumPacketWriter> writer, |
| - scoped_refptr<StringIOBuffer> packet) { |
| + std::unique_ptr<QuicChromiumPacketWriter> writer) { |
| DCHECK_EQ(sockets_.size(), packet_readers_.size()); |
| if (sockets_.size() >= kMaxReadersPerQuicSession) { |
| + packet_ = nullptr; |
| return false; |
| } |
| + |
| // TODO(jri): Make SetQuicPacketWriter take a scoped_ptr. |
| packet_readers_.push_back(std::move(reader)); |
| sockets_.push_back(std::move(socket)); |
| StartReading(); |
| - QuicChromiumPacketWriter* raw_writer = writer.get(); |
| connection()->SetQuicPacketWriter(writer.release(), /*owns_writer=*/true); |
| - if (packet == nullptr) { |
| - connection()->SendPing(); |
| - return true; |
| - } |
| - // Packet rewrite after migration on socket write error. |
| - error_code_from_rewrite_ = raw_writer->WritePacketToSocket(packet.get()); |
| - use_error_code_from_rewrite_ = true; |
| + |
| + // Post task to write the pending packet or a PING packet to the new socket. |
| + task_runner_->PostTask( |
| + FROM_HERE, base::Bind(&QuicChromiumClientSession::WriteToNewSocket, |
| + weak_factory_.GetWeakPtr(), packet_)); |
|
Ryan Hamilton
2016/09/10 16:29:46
Since we're not writing immediately, I think we ne
Jana
2016/09/10 23:08:31
Good point. I'll add a ShouldWriteBlock to the del
|
| + |
| + // Reset packet_ since (i) the posted write can result in a write |
| + // error, causing packet_ to be used again, and (ii) avoids a later |
| + // migration attempt if any pending migration task is executed. |
| + packet_ = nullptr; |
|
Ryan Hamilton
2016/09/10 16:29:47
Is (i) actually correct? If I understand correctly
Jana
2016/09/10 23:08:31
Right, I think the comment wasn't clear -- but I'v
|
| return true; |
| } |