chrome-devtools-protocol
chrome-devtools-protocol copied to clipboard
Socket exception makes it impossible to cleanly close session
If there's an issue that closes the WebSocket connection, it's not longer possible to cleanly close the session.
If you call Session::close() on the session object after an issue that closes the WebSocket connection (likely after catching an exception resulting from that closed WebSocket connection), Session::close() will attempt to send messages to the disconnected WebSocket. That will cause an exception.
If you catch that exception, execution in Session::close() will never get to the line that closes the DevtoolsClient: "$this->browser->close();"
If DevtoolsClient::close() is never called, the LogicException in DevtoolsClient::__destruct() will be thrown, complaining that the (broken) WebSocket connection was never released.
Put another way:
- Instance::open() creates a Tab. You can create and get the DevtoolsClient using $tab->devtools(). You can call $devtools->close() directly.
- On the other hand, Instance::createSession() creates a Session. The DevtoolsClient is created implicitly, and you cannot get it. You can only close in indirectly by closing the Session, and if the Session closing process throws an exception, code execution will never reach the line in Session::close() that calls DevtoolsClient::close(). This results in DevtoolsClient::__destruct() throwing the exception seen inside.