bug 1523104: remote: destroy the related Session when the WebSocket connection drops; r=ato
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 05 Mar 2019 12:57:04 -0800
changeset 521122 f9eb88415e06
parent 521121 45eecaf3a611
child 521123 e43dbe94d1aa
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1523104
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1523104: remote: destroy the related Session when the WebSocket connection drops; r=ato
remote/TargetListener.jsm
--- a/remote/TargetListener.jsm
+++ b/remote/TargetListener.jsm
@@ -59,19 +59,35 @@ class TargetListener {
    *
    * @param String eventName
    * @param WebSocketDebuggerTransport transport
    * @param SocketListener listener
    */
   onConnectionAccepted(eventName, transport, listener) {
     const conn = new Connection(this.nextConnID++, transport);
     transport.ready();
+    transport.on("close", this.onConnectionClosed.bind(this, conn));
     this.sessions.set(conn, new Session(conn, this.target));
   }
 
+  /**
+   * WebSocketTransport's `close` listener. Called whenever a new WebSocket connection is
+   * closed.
+   *
+   * @param Connection conn
+   * @param String eventName
+   */
+  onConnectionClosed(conn, eventName) {
+    const session = this.sessions.get(conn);
+    if (!session) {
+      return;
+    }
+    session.destructor();
+  }
+
   get url() {
     if (this.listening) {
       const {network, host, port} = this.listener;
       return `${network}://${host}:${port}/`;
     }
     return null;
   }