Commit c35a2211 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

serial: Ensure close callback is always executed

This change fixes SerialIoHandler::Close() to ensure that the callback
is always executed even if there isn't a file handle to close. Failing
to do so will trigger a DCHECK in the Mojo bindings layer and could
cause clients of the Mojo interface to stall waiting for a response.

Bug: 884928
Change-Id: I272cc1987627232dc2143380071a07b7c58fb2cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354775
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798115}
parent 743d03e9
......@@ -174,6 +174,8 @@ void SerialIoHandler::Close(base::OnceClosure callback) {
{base::MayBlock(), base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
base::BindOnce(&SerialIoHandler::DoClose, std::move(file_)),
std::move(callback));
} else {
std::move(callback).Run();
}
}
......
......@@ -214,4 +214,14 @@ TEST_F(SerialPortImplTest, Drain) {
loop.Run();
}
TEST_F(SerialPortImplTest, Close) {
mojo::Remote<mojom::SerialPort> serial_port;
mojo::SelfOwnedReceiverRef<mojom::SerialPortConnectionWatcher> watcher;
CreatePort(&serial_port, &watcher);
base::RunLoop loop;
serial_port->Close(loop.QuitClosure());
loop.Run();
}
} // namespace device
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment