Turasa / libsignal-service-java

GNU General Public License v3.0
39 stars 22 forks source link

WebSocketConnection mem leak #16

Open Trolldemorted opened 6 years ago

Trolldemorted commented 6 years ago
  @Override
  public synchronized void onMessage(WebSocket webSocket, ByteString payload) {
    Log.w(TAG, "WSC onMessage()");
    try {
      WebSocketMessage message = WebSocketMessage.parseFrom(payload.toByteArray());

      Log.w(TAG, "Message Type: " + message.getType().getNumber());

      if (message.getType().getNumber() == WebSocketMessage.Type.REQUEST_VALUE)  {
        incomingRequests.add(message.getRequest());
      } else if (message.getType().getNumber() == WebSocketMessage.Type.RESPONSE_VALUE) {
        SettableFuture<Pair<Integer, String>> listener = outgoingRequests.get(message.getResponse().getId());
        if (listener != null) listener.set(new Pair<>(message.getResponse().getStatus(),
                                                      new String(message.getResponse().getBody().toByteArray())));
      }

      notifyAll();
    } catch (InvalidProtocolBufferException e) {
      Log.w(TAG, e);
}

Whenever we send a message it gets added to outgoingRequests, so that the settable future can be fulfilled when confirmation arrives. However, even if it does, the reference to the future is not removed from the map, that only happens in onClosed - which I assume does not happen frequently when the ws connection is permanently open, e.g. in signal-cli in debus mode or Signal-Android without play services (?).

cc @golf1052 @mitchcapper our libsignal is affected by this issue as well